struct File [src]
Fields
prefixed_path: PrefixedPath
max_file_size: ?usize
handle: ?fs.FilePopulated if the user calls addOpenedFile.
The handle is not owned here.
stat: Stat
bin_digest: BinDigest
contents: ?[]const u8
Members
- deinit (Function)
- Stat (struct)
- updateHandle (Function)
- updateMaxSize (Function)
Source
pub const File = struct {
prefixed_path: PrefixedPath,
max_file_size: ?usize,
/// Populated if the user calls `addOpenedFile`.
/// The handle is not owned here.
handle: ?fs.File,
stat: Stat,
bin_digest: BinDigest,
contents: ?[]const u8,
pub const Stat = struct {
inode: fs.File.INode,
size: u64,
mtime: i128,
pub fn fromFs(fs_stat: fs.File.Stat) Stat {
return .{
.inode = fs_stat.inode,
.size = fs_stat.size,
.mtime = fs_stat.mtime,
};
}
};
pub fn deinit(self: *File, gpa: Allocator) void {
gpa.free(self.prefixed_path.sub_path);
if (self.contents) |contents| {
gpa.free(contents);
self.contents = null;
}
self.* = undefined;
}
pub fn updateMaxSize(file: *File, new_max_size: ?usize) void {
const new = new_max_size orelse return;
file.max_file_size = if (file.max_file_size) |old| @max(old, new) else new;
}
pub fn updateHandle(file: *File, new_handle: ?fs.File) void {
const handle = new_handle orelse return;
file.handle = handle;
}
}