Files
herolib/lib/vfs/vfscore/interface.v
Mahmoud Emad 383fc9fade feat: Improve OurDBFS ID generation and data persistence
- Use a counter for consistent ID generation in OurDBFS: This
  eliminates reliance on timestamps, preventing ID collisions and
  improving data integrity.
- Refactor save methods to directly use the VFS's save_entry
  function: This simplifies the code and reduces redundancy across
  different file system entity types (Directory, File, Symlink).
- Update `save_entry` in OurDBFS to use IDs for database updates:
  This ensures data is correctly updated in the database based on the
  unique ID of each entry.  This also fixes potential issues with
  overwriting data.
2025-02-19 01:12:19 +02:00

60 lines
1.4 KiB
V

module vfscore
// FileType represents the type of a filesystem entry
pub enum FileType {
file
directory
symlink
}
// Metadata represents the common metadata for both files and directories
pub struct Metadata {
pub mut:
id u32 // name of file or directory
name string // name of file or directory
file_type FileType
size u64
created_at i64 // unix epoch timestamp
modified_at i64 // unix epoch timestamp
accessed_at i64 // unix epoch timestamp
}
// FSEntry represents a filesystem entry (file, directory, or symlink)
pub interface FSEntry {
get_metadata() Metadata
get_path() string
}
// VFSImplementation defines the interface that all vfscore implementations must follow
pub interface VFSImplementation {
mut:
// Basic operations
root_get() !FSEntry
// File operations
file_create(path string) !FSEntry
file_read(path string) ![]u8
file_write(path string, data []u8) !
file_delete(path string) !
// Directory operations
dir_create(path string) !FSEntry
dir_list(path string) ![]FSEntry
dir_delete(path string) !
// Common operations
exists(path string) bool
get(path string) !FSEntry
rename(old_path string, new_path string) !
copy(src_path string, dst_path string) !
delete(path string) !
// Symlink operations
link_create(target_path string, link_path string) !FSEntry
link_read(path string) !string
link_delete(path string) !
// Cleanup operation
destroy() !
}