WIP: Fixing the tests
This commit is contained in:
@@ -17,17 +17,17 @@ fn encode_metadata(mut e encoder.Encoder, m Metadata) {
|
||||
}
|
||||
|
||||
// decode_metadata decodes the common metadata structure
|
||||
fn decode_metadata(mut d encoder.Decoder) Metadata {
|
||||
id := d.get_u32()
|
||||
name := d.get_string()
|
||||
file_type_byte := d.get_u8()
|
||||
size := d.get_u64()
|
||||
created_at := d.get_i64()
|
||||
modified_at := d.get_i64()
|
||||
accessed_at := d.get_i64()
|
||||
mode := d.get_u32()
|
||||
owner := d.get_string()
|
||||
group := d.get_string()
|
||||
fn decode_metadata(mut d encoder.Decoder) !Metadata {
|
||||
id := d.get_u32()!
|
||||
name := d.get_string()!
|
||||
file_type_byte := d.get_u8()!
|
||||
size := d.get_u64()!
|
||||
created_at := d.get_i64()!
|
||||
modified_at := d.get_i64()!
|
||||
accessed_at := d.get_i64()!
|
||||
mode := d.get_u32()!
|
||||
owner := d.get_string()!
|
||||
group := d.get_string()!
|
||||
|
||||
return Metadata{
|
||||
id: id
|
||||
@@ -69,28 +69,28 @@ pub fn (dir Directory) encode() []u8 {
|
||||
// decode_directory decodes a binary format back to Directory
|
||||
pub fn decode_directory(data []u8) !Directory {
|
||||
mut d := encoder.decoder_new(data)
|
||||
version := d.get_u8()
|
||||
version := d.get_u8()!
|
||||
if version != 1 {
|
||||
return error('Unsupported version ${version}')
|
||||
}
|
||||
|
||||
type_byte := d.get_u8()
|
||||
type_byte := d.get_u8()!
|
||||
if type_byte != u8(FileType.directory) {
|
||||
return error('Invalid type byte for directory')
|
||||
}
|
||||
|
||||
// Decode metadata
|
||||
metadata := decode_metadata(mut d)
|
||||
metadata := decode_metadata(mut d)!
|
||||
|
||||
// Decode parent_id
|
||||
parent_id := d.get_u32()
|
||||
parent_id := d.get_u32()!
|
||||
|
||||
// Decode children IDs
|
||||
children_count := int(d.get_u16())
|
||||
children_count := int(d.get_u16()!)
|
||||
mut children := []u32{cap: children_count}
|
||||
|
||||
for _ in 0 .. children_count {
|
||||
children << d.get_u32()
|
||||
children << d.get_u32()!
|
||||
}
|
||||
|
||||
return Directory{
|
||||
@@ -124,24 +124,24 @@ pub fn (f File) encode() []u8 {
|
||||
// decode_file decodes a binary format back to File
|
||||
pub fn decode_file(data []u8) !File {
|
||||
mut d := encoder.decoder_new(data)
|
||||
version := d.get_u8()
|
||||
version := d.get_u8()!
|
||||
if version != 1 {
|
||||
return error('Unsupported version ${version}')
|
||||
}
|
||||
|
||||
type_byte := d.get_u8()
|
||||
type_byte := d.get_u8()!
|
||||
if type_byte != u8(FileType.file) {
|
||||
return error('Invalid type byte for file')
|
||||
}
|
||||
|
||||
// Decode metadata
|
||||
metadata := decode_metadata(mut d)
|
||||
metadata := decode_metadata(mut d)!
|
||||
|
||||
// Decode parent_id
|
||||
parent_id := d.get_u32()
|
||||
parent_id := d.get_u32()!
|
||||
|
||||
// Decode file data
|
||||
data_content := d.get_string()
|
||||
data_content := d.get_string()!
|
||||
|
||||
return File{
|
||||
metadata: metadata
|
||||
@@ -174,24 +174,24 @@ pub fn (sl Symlink) encode() []u8 {
|
||||
// decode_symlink decodes a binary format back to Symlink
|
||||
pub fn decode_symlink(data []u8) !Symlink {
|
||||
mut d := encoder.decoder_new(data)
|
||||
version := d.get_u8()
|
||||
version := d.get_u8()!
|
||||
if version != 1 {
|
||||
return error('Unsupported version ${version}')
|
||||
}
|
||||
|
||||
type_byte := d.get_u8()
|
||||
type_byte := d.get_u8()!
|
||||
if type_byte != u8(FileType.symlink) {
|
||||
return error('Invalid type byte for symlink')
|
||||
}
|
||||
|
||||
// Decode metadata
|
||||
metadata := decode_metadata(mut d)
|
||||
metadata := decode_metadata(mut d)!
|
||||
|
||||
// Decode parent_id
|
||||
parent_id := d.get_u32()
|
||||
parent_id := d.get_u32()!
|
||||
|
||||
// Decode target path
|
||||
target := d.get_string()
|
||||
target := d.get_string()!
|
||||
|
||||
return Symlink{
|
||||
metadata: metadata
|
||||
|
||||
@@ -72,19 +72,19 @@ pub fn (mut fs OurDBFS) save_entry(entry FSEntry) !u32 {
|
||||
match entry {
|
||||
Directory {
|
||||
encoded := entry.encode()
|
||||
return fs.db_meta.set(entry.metadata.id, encoded) or {
|
||||
return fs.db_meta.set(id: entry.metadata.id, data: encoded) or {
|
||||
return error('Failed to save directory on id:${entry.metadata.id}: ${err}')
|
||||
}
|
||||
}
|
||||
File {
|
||||
encoded := entry.encode()
|
||||
return fs.db_meta.set(entry.metadata.id, encoded) or {
|
||||
return fs.db_meta.set(id: entry.metadata.id, data: encoded) or {
|
||||
return error('Failed to save file on id:${entry.metadata.id}: ${err}')
|
||||
}
|
||||
}
|
||||
Symlink {
|
||||
encoded := entry.encode()
|
||||
return fs.db_meta.set(entry.metadata.id, encoded) or {
|
||||
return fs.db_meta.set(id: entry.metadata.id, data: encoded) or {
|
||||
return error('Failed to save symlink on id:${entry.metadata.id}: ${err}')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ fn test_vfs_implementations() ! {
|
||||
// Cleanup
|
||||
local_vfs.delete('test2.txt')!
|
||||
local_vfs.delete('subdir')!
|
||||
local_vfs.delete('test_link.txt')!
|
||||
local_vfs.delete('test_link.txt') or {}
|
||||
|
||||
os.rmdir('/tmp/test_local_vfs') or {}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
module vfsnested
|
||||
|
||||
import freeflowuniverse.herolib.vfs.vfscore
|
||||
import os
|
||||
|
||||
fn test_nested() ! {
|
||||
|
||||
@@ -8,7 +8,7 @@ import time
|
||||
// OurDBVFS represents a VFS that uses OurDB as the underlying storage
|
||||
pub struct OurDBVFS {
|
||||
mut:
|
||||
core &ourdb_fs.VFS
|
||||
core &ourdb_fs.OurDBFS
|
||||
}
|
||||
|
||||
// new creates a new OurDBVFS instance
|
||||
@@ -155,20 +155,19 @@ 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()!
|
||||
return *self.core.get_root()! // Dereference to return a value
|
||||
}
|
||||
|
||||
mut current := self.core.get_root()!
|
||||
mut current := self.core.get_root()! // This is already a reference (&Directory)
|
||||
parts := path.trim_left('/').split('/')
|
||||
|
||||
for i := 0; i < parts.len; i++ {
|
||||
found := false
|
||||
children := current.children(false)!
|
||||
mut found := false
|
||||
mut children := current.children(false)!
|
||||
|
||||
for child in children {
|
||||
for mut child in children {
|
||||
if child.metadata.name == parts[i] {
|
||||
match child {
|
||||
ourdb_fs.Directory {
|
||||
@@ -178,7 +177,7 @@ fn (mut self OurDBVFS) get_entry(path string) !ourdb_fs.FSEntry {
|
||||
}
|
||||
else {
|
||||
if i == parts.len - 1 {
|
||||
return child
|
||||
return child // `child` is already a value, so return it directly
|
||||
} else {
|
||||
return error('Not a directory: ${parts[i]}')
|
||||
}
|
||||
@@ -192,7 +191,7 @@ fn (mut self OurDBVFS) get_entry(path string) !ourdb_fs.FSEntry {
|
||||
}
|
||||
}
|
||||
|
||||
return current
|
||||
return *current // Dereference to return a value
|
||||
}
|
||||
|
||||
fn (mut self OurDBVFS) get_directory(path string) !&ourdb_fs.Directory {
|
||||
|
||||
Reference in New Issue
Block a user