feat: file size

This commit is contained in:
2025-06-06 16:55:25 +02:00
parent 3e3f03f11a
commit feeff8cc3e
3 changed files with 40 additions and 3 deletions

View File

@@ -39,6 +39,7 @@ pub const ItemEnum = union(enum) {
pub const Element = struct {
item: Item,
content_size: u64,
fn deinit(self: *Element) void {
self.item.allocator.destroy(self);

View File

@@ -89,7 +89,10 @@ pub const LocalContentProvider = struct {
const native_path = try getNativePathByFullName(allocator, fullName);
defer allocator.free(native_path);
const kind: union(enum) { directory, file } = blk: {
const kind: union(enum) {
directory,
file: struct { size: u64 },
} = blk: {
// FIXME: properly handle different errors
var dir = std.fs.cwd().openDir(native_path, .{});
if (dir) |*d| {
@@ -99,8 +102,12 @@ pub const LocalContentProvider = struct {
var file = std.fs.cwd().openFile(native_path, .{});
if (file) |*f| {
const size = size: {
const stat = f.stat() catch break :size 0;
break :size stat.size;
};
f.close();
break :blk .file;
break :blk .{ .file = .{ .size = size } };
} else |_| {}
return GetItemsError.NotExists;
@@ -136,10 +143,11 @@ pub const LocalContentProvider = struct {
break :blk &container.item;
},
.file => blk: {
.file => |file| blk: {
const element = try allocator.create(Element);
element.* = Element{
.item = undefined,
.content_size = file.size,
};
const val: ItemEnum = .{