feat: file size
This commit is contained in:
@@ -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 = .{
|
||||
|
||||
Reference in New Issue
Block a user