diff --git a/lib/data/ourdb/db.v b/lib/data/ourdb/db.v index 121d4a74..a9f6e40c 100644 --- a/lib/data/ourdb/db.v +++ b/lib/data/ourdb/db.v @@ -29,14 +29,16 @@ pub fn (mut db OurDB) set(args OurDBSetArgs) !u32 { // if id points to an empty location, return an error // else, overwrite data if id := args.id { - // this is an update - location := db.lookup.get(id)! - if location.position == 0 { - return error('cannot set id for insertions when incremental mode is enabled') - } + if id != 0 { + // this is an update + location := db.lookup.get(id)! + if location.position == 0 { + return error('cannot set id for insertions when incremental mode is enabled') + } - db.set_(id, location, args.data)! - return id + db.set_(id, location, args.data)! + return id + } } // this is an insert diff --git a/lib/vfs/ourdb_fs/vfs.v b/lib/vfs/ourdb_fs/vfs.v index 7a7d99ef..20d4ffbf 100644 --- a/lib/vfs/ourdb_fs/vfs.v +++ b/lib/vfs/ourdb_fs/vfs.v @@ -26,7 +26,9 @@ pub fn (mut fs OurDBFS) get_root() !&Directory { } // Save new root to DB mut myroot := Directory{ - metadata: Metadata{} + metadata: Metadata{ + file_type: .directory + } parent_id: 0 myvfs: &fs } diff --git a/lib/vfs/vfsourdb/vfsourdb.v b/lib/vfs/vfsourdb/vfsourdb.v index 20019124..56b13e2d 100644 --- a/lib/vfs/vfsourdb/vfsourdb.v +++ b/lib/vfs/vfsourdb/vfsourdb.v @@ -66,8 +66,10 @@ pub fn (mut self OurDBVFS) file_delete(path string) ! { } pub fn (mut self OurDBVFS) dir_create(path string) !vfscore.FSEntry { + println('Debug: Creating directory ${path}') parent_path := os.dir(path) dir_name := os.base(path) + println('Debug: Creating directory ${dir_name} in ${parent_path}') mut parent_dir := self.get_directory(parent_path)! mut new_dir := parent_dir.mkdir(dir_name)! @@ -157,15 +159,18 @@ pub fn (mut self OurDBVFS) destroy() ! { // Helper functions fn (mut self OurDBVFS) get_entry(path string) !ourdb_fs.FSEntry { if path == '/' { - return *self.core.get_root()! // Dereference to return a value + return *self.core.get_root()! } - mut current := self.core.get_root()! // This is already a reference (&Directory) + mut current := self.core.get_root()! parts := path.trim_left('/').split('/') + println('parts: ${parts}') + println('current: ${current}') for i := 0; i < parts.len; i++ { mut found := false mut children := current.children(false)! + println('children: ${children}') for mut child in children { if child.metadata.name == parts[i] { @@ -174,12 +179,13 @@ fn (mut self OurDBVFS) get_entry(path string) !ourdb_fs.FSEntry { unsafe { current = child } + println('Debug: current: ${current}') found = true break } else { if i == parts.len - 1 { - return child // `child` is already a value, so return it directly + return child } else { return error('Not a directory: ${parts[i]}') } @@ -193,7 +199,7 @@ fn (mut self OurDBVFS) get_entry(path string) !ourdb_fs.FSEntry { } } - return *current // Dereference to return a value + return *current } fn (mut self OurDBVFS) get_directory(path string) !&ourdb_fs.Directory { diff --git a/lib/vfs/vfsourdb/vfsourdb_test.v b/lib/vfs/vfsourdb/vfsourdb_test.v index 6e8eca0f..a3b5279c 100644 --- a/lib/vfs/vfsourdb/vfsourdb_test.v +++ b/lib/vfs/vfsourdb/vfsourdb_test.v @@ -26,7 +26,7 @@ fn test_vfsourdb() ! { assert root.get_metadata().name == '' // Test directory creation - mut test_dir := vfs.dir_create('/test_dir')! + mut test_dir := vfs.dir_create('/tmp/test_dir')! assert test_dir.get_metadata().name == 'test_dir' assert test_dir.get_metadata().file_type == .directory