Added the ability to close a directory node
Updated docs Closes #270 Update doc comment Moved close to closeFile and closeDir in VFS Moved back to @ptrCast() Always forget to format Added TODO comment
This commit is contained in:
parent
e2e105a1f9
commit
0497beb5c6
3 changed files with 53 additions and 29 deletions
|
@ -87,13 +87,13 @@ pub const FileSystem = struct {
|
|||
const Self = @This();
|
||||
|
||||
///
|
||||
/// Close an open file, performing any last operations required to save data etc.
|
||||
/// Close an open node, performing any last operations required to save data etc.
|
||||
///
|
||||
/// Arguments:
|
||||
/// IN self: *const FileSystem - The filesystem in question being operated on.
|
||||
/// IN node: *const FileNode - The file being closed
|
||||
/// IN node: *const Node - The node being closed.
|
||||
///
|
||||
const Close = fn (self: *const Self, node: *const FileNode) void;
|
||||
const Close = fn (self: *const Self, node: *const Node) void;
|
||||
|
||||
///
|
||||
/// Read from an open file
|
||||
|
@ -191,7 +191,8 @@ pub const FileNode = struct {
|
|||
|
||||
/// See the documentation for FileSystem.Close
|
||||
pub fn close(self: *const FileNode) void {
|
||||
return self.fs.close(self.fs, self);
|
||||
// TODO: Use @fieldParentPtr() once implemented for unions
|
||||
return self.fs.close(self.fs, @ptrCast(*const Node, self));
|
||||
}
|
||||
|
||||
/// See the documentation for FileSystem.Write
|
||||
|
@ -218,6 +219,18 @@ pub const DirNode = struct {
|
|||
}
|
||||
return fs.open(fs, node, name, flags, args);
|
||||
}
|
||||
|
||||
/// See the documentation for FileSystem.Close
|
||||
pub fn close(self: *const DirNode) void {
|
||||
var fs = self.fs;
|
||||
var node = self;
|
||||
if (self.mount) |mnt| {
|
||||
fs = mnt.fs;
|
||||
node = mnt;
|
||||
}
|
||||
// TODO: Use @fieldParentPtr() once implemented for unions
|
||||
return fs.close(fs, @ptrCast(*const Node, node));
|
||||
}
|
||||
};
|
||||
|
||||
/// Errors that can be thrown by filesystem functions
|
||||
|
@ -574,7 +587,7 @@ const TestFS = struct {
|
|||
return &test_fs.tree.val.Dir;
|
||||
}
|
||||
|
||||
fn close(fs: *const FileSystem, node: *const FileNode) void {
|
||||
fn close(fs: *const FileSystem, node: *const Node) void {
|
||||
var test_fs = @fieldParentPtr(TestFS, "instance", fs.instance);
|
||||
test_fs.open_files_count -= 1;
|
||||
}
|
||||
|
@ -680,7 +693,14 @@ fn testInitFs(allocator: *Allocator) !*TestFS {
|
|||
.allocator = allocator,
|
||||
};
|
||||
testfs.tree.children.* = ArrayList(*TestFS.TreeNode).init(allocator);
|
||||
fs.* = .{ .open = TestFS.open, .close = TestFS.close, .read = TestFS.read, .write = TestFS.write, .instance = &testfs.instance, .getRootNode = TestFS.getRootNode };
|
||||
fs.* = .{
|
||||
.open = TestFS.open,
|
||||
.close = TestFS.close,
|
||||
.read = TestFS.read,
|
||||
.write = TestFS.write,
|
||||
.instance = &testfs.instance,
|
||||
.getRootNode = TestFS.getRootNode,
|
||||
};
|
||||
return testfs;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue