Skip to content

Commit

Permalink
Convert: create target file if it doesn't yet exist (#160)
Browse files Browse the repository at this point in the history
* Convert: create target file if it doesn't yet exist

also: use with absolute filenames, otherwise 'file.exists' and friends
don't work

* fmt
  • Loading branch information
mpollmeier authored Mar 20, 2024
1 parent 4c62caf commit df10f92
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import scala.collection.mutable
object Deserialization {

def readGraph(storagePath: Path, schemaMaybe: Option[Schema], persistOnClose: Boolean = true): Graph = {
val fileChannel = new java.io.RandomAccessFile(storagePath.toFile, "r").getChannel
val fileChannel = new java.io.RandomAccessFile(storagePath.toAbsolutePath.toFile, "r").getChannel
try {
// fixme: Use convenience methods from schema to translate string->id. Fix after we get strict schema checking.
val manifest = readManifest(fileChannel)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/flatgraph/storage/Serialization.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object Serialization {

val fileChannel =
new java.io.RandomAccessFile(
storagePath.toFile,
storagePath.toAbsolutePath.toFile,
"rw"
).getChannel // if (conf.filename != null) { new java.io.RandomAccessFile("/tmp/foo.fg", "w").getChannel }}
try {
Expand Down
9 changes: 7 additions & 2 deletions odb-convert/src/main/scala/flatgraph/convert/Convert.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ object Convert {
}

private def writeData(filename: File, nodeStuff: Array[NodeStuff], strings: Array[String]): Unit = {
val filePtr = new AtomicLong(16)
val fileChannel = new java.io.RandomAccessFile(filename, "rw").getChannel
val fileAbsolute = filename.getAbsoluteFile
val filePtr = new AtomicLong(16)
if (!fileAbsolute.exists()) {
fileAbsolute.getParentFile.mkdirs()
fileAbsolute.createNewFile()
}
val fileChannel = new java.io.RandomAccessFile(fileAbsolute, "rw").getChannel
try {
val nodes = nodeStuff.map { ns => new Manifest.NodeItem(ns.label, ns.nextId, null) }
val edges = mutable.ArrayBuffer[Manifest.EdgeItem]()
Expand Down

0 comments on commit df10f92

Please sign in to comment.