diff options
author | 2021-04-26 19:22:17 -0700 | |
---|---|---|
committer | 2021-04-26 19:22:17 -0700 | |
commit | 70b6f889c7509ae6944469e1c45ed9b755b2ceec (patch) | |
tree | e8c7d48c576fbaed33046c557c959d85c5c35c1e /src/fs.zig | |
parent | 97ce2513dc71271503ebd746ac5e9e0f57858bb7 (diff) | |
download | bun-70b6f889c7509ae6944469e1c45ed9b755b2ceec.tar.gz bun-70b6f889c7509ae6944469e1c45ed9b755b2ceec.tar.zst bun-70b6f889c7509ae6944469e1c45ed9b755b2ceec.zip |
lots
Diffstat (limited to 'src/fs.zig')
-rw-r--r-- | src/fs.zig | 72 |
1 files changed, 64 insertions, 8 deletions
diff --git a/src/fs.zig b/src/fs.zig index 4f2918412..82302b697 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -7,19 +7,75 @@ const expect = std.testing.expect; // pub const FilesystemImplementation = @import("fs_impl.zig"); -pub const FileSystem = struct { tree: std.AutoHashMap(FileSystemEntry) }; +// +pub const Stat = packed struct { + // milliseconds + mtime: i64 = 0, + // last queried timestamp + qtime: i64 = 0, + kind: FileSystemEntry.Kind, +}; + +pub const FileSystem = struct { + // This maps paths relative to absolute_working_dir to the structure of arrays of paths + stats: std.StringHashMap(Stat) = undefined, + entries: std.ArrayList(FileSystemEntry), + + absolute_working_dir = "/", + implementation: anytype = undefined, + + // pub fn statBatch(fs: *FileSystemEntry, paths: []string) ![]?Stat { + + // } + // pub fn stat(fs: *FileSystemEntry, path: string) !Stat { + + // } + // pub fn readFile(fs: *FileSystemEntry, path: string) ?string { -pub const FileSystemEntry = union(enum) { + // } + // pub fn readDir(fs: *FileSystemEntry, path: string) ?[]string { + + // } + + pub fn Implementation(comptime Context: type) type { + return struct { + context: *Context, + + pub fn statBatch(context: *Context, path: string) ![]?Stat { + return try context.statBatch(path); + } + + pub fn stat(context: *Context, path: string) !?Stat { + return try context.stat(path); + } + + pub fn readFile(context: *Context, path: string) !?File { + return try context.readFile(path); + } + + pub fn readDir(context: *Context, path: string) []string { + return context.readdir(path); + } + }; + } +}; + +pub const FileNotFound = struct {}; + +pub const FileSystemEntry = union(FileSystemEntry.Kind) { file: File, directory: Directory, -}; + not_found: FileNotFound, -pub const File = struct { - path: Path, - mtime: ?usize, - contents: ?string, + pub const Kind = enum(u8) { + file, + directory, + not_found, + }; }; -pub const Directory = struct { path: Path, mtime: ?usize, contents: []FileSystemEntry }; + +pub const Directory = struct { path: Path, contents: []string }; +pub const File = struct { path: Path, contents: string }; pub const PathName = struct { base: string, |