- Fixed ID generation for files and directories in OurDBFS, preventing collisions and improving data integrity. This ensures that IDs are consistently and uniquely assigned. - Updated save methods to correctly update the `metadata.id` field across all FSEntry types (File, Directory, Symlink). This change solves a previous issue where IDs weren't being properly persisted. - Added incremental mode to OurDB, improving performance for large datasets. This allows for more efficient updates instead of full overwrites.
32 lines
674 B
V
32 lines
674 B
V
module ourdb_fs
|
|
|
|
import time
|
|
|
|
// File represents a file in the virtual filesystem
|
|
pub struct File {
|
|
pub mut:
|
|
metadata Metadata // Metadata from models_common.v
|
|
data string // File content stored in DB
|
|
parent_id u32 // ID of parent directory
|
|
myvfs &OurDBFS @[skip]
|
|
}
|
|
|
|
pub fn (mut f File) save() ! {
|
|
f.metadata.id = f.myvfs.save_entry(f)!
|
|
}
|
|
|
|
// write updates the file's content
|
|
pub fn (mut f File) write(content string) ! {
|
|
f.data = content
|
|
f.metadata.size = u64(content.len)
|
|
f.metadata.modified_at = time.now().unix()
|
|
|
|
// Save updated file to DB
|
|
f.save()!
|
|
}
|
|
|
|
// read returns the file's content
|
|
pub fn (mut f File) read() !string {
|
|
return f.data
|
|
}
|