feat(windows): fix windows bugs
This commit is contained in:
@@ -19,8 +19,8 @@ fn loadChildren(container: *Container) void {
|
||||
}
|
||||
|
||||
var dir = std.fs.cwd().openDir(container.item.nativePath.path, .{ .iterate = true }) catch {
|
||||
const errorContent = std.fmt.allocPrint(container.item.allocator, "Could not open directory '{s}'.", .{container.item.nativePath.path}) catch return;
|
||||
container.item.errors.append(.{ .content = errorContent }) catch return;
|
||||
// const errorContent = std.fmt.allocPrint(container.item.allocator, "Could not open directory '{s}'.", .{container.item.nativePath.path}) catch return;
|
||||
// container.item.errors.append(.{ .content = errorContent }) catch return;
|
||||
return;
|
||||
};
|
||||
defer dir.close();
|
||||
@@ -56,9 +56,27 @@ pub const LocalContentProvider = struct {
|
||||
initContext: *const InitContext,
|
||||
allocator: std.mem.Allocator,
|
||||
) GetItemsError!*Item {
|
||||
const stat = std.fs.cwd().statFile(fullName.path) catch return GetItemsError.NotExists;
|
||||
const path = try std.mem.replaceOwned(u8, allocator, fullName.path, "/", "\\");
|
||||
defer allocator.free(path);
|
||||
|
||||
return switch (stat.kind) {
|
||||
const kind: union(enum) { directory, file } = blk: {
|
||||
// FIXME: properly handle different errors
|
||||
var dir = std.fs.cwd().openDir(path, .{});
|
||||
if (dir) |*d| {
|
||||
d.close();
|
||||
break :blk .directory;
|
||||
} else |_| {}
|
||||
|
||||
var file = std.fs.cwd().openFile(path, .{});
|
||||
if (file) |*f| {
|
||||
f.close();
|
||||
break :blk .file;
|
||||
} else |_| {}
|
||||
|
||||
return GetItemsError.NotExists;
|
||||
};
|
||||
|
||||
return switch (kind) {
|
||||
.directory => blk: {
|
||||
const container = try allocator.create(Container);
|
||||
container.* = Container{
|
||||
@@ -106,9 +124,6 @@ pub const LocalContentProvider = struct {
|
||||
|
||||
break :blk &element.item;
|
||||
},
|
||||
else => @panic(
|
||||
"Unsupported file type\n",
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ pub const VTable = struct {
|
||||
pub const GetItemsError = error{
|
||||
OutOfMemory,
|
||||
NotExists,
|
||||
NotSupported,
|
||||
};
|
||||
|
||||
pub const Provider = struct {
|
||||
|
||||
@@ -17,7 +17,7 @@ pub const Tab = struct {
|
||||
_private: Private,
|
||||
|
||||
const Private = struct {
|
||||
currentItemsAllocator: ?std.heap.ArenaAllocator,
|
||||
currentItemsAllocator: std.heap.ArenaAllocator,
|
||||
};
|
||||
|
||||
pub fn init(
|
||||
@@ -31,7 +31,7 @@ pub const Tab = struct {
|
||||
.currentLocation = null,
|
||||
.threadPool = threadPool,
|
||||
._private = .{
|
||||
.currentItemsAllocator = null,
|
||||
.currentItemsAllocator = std.heap.ArenaAllocator.init(allocator),
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -51,9 +51,7 @@ pub const Tab = struct {
|
||||
loadItems(self, location) catch return;
|
||||
}
|
||||
fn loadItems(self: *Tab, location: *Container) !void {
|
||||
if (self._private.currentItemsAllocator) |arena| {
|
||||
arena.deinit();
|
||||
}
|
||||
_ = self._private.currentItemsAllocator.reset(.retain_capacity);
|
||||
|
||||
{
|
||||
self.currentItems.mutex.lock();
|
||||
@@ -63,16 +61,14 @@ pub const Tab = struct {
|
||||
}
|
||||
}
|
||||
|
||||
self._private.currentItemsAllocator = std.heap.ArenaAllocator.init(self.allocator);
|
||||
const arenaAllocator = &self._private.currentItemsAllocator.?;
|
||||
const arenaAllocator = &self._private.currentItemsAllocator;
|
||||
const arena = arenaAllocator.allocator();
|
||||
|
||||
var threadSafeAllocator = std.heap.ThreadSafeAllocator{ .child_allocator = arena };
|
||||
const allocator = threadSafeAllocator.allocator();
|
||||
|
||||
errdefer {
|
||||
arenaAllocator.deinit();
|
||||
self._private.currentItemsAllocator = null;
|
||||
_ = self._private.currentItemsAllocator.reset(.free_all);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -80,18 +76,23 @@ pub const Tab = struct {
|
||||
defer self.currentItems.mutex.unlock();
|
||||
|
||||
self.currentItems.data = std.ArrayList(*Item).init(allocator);
|
||||
errdefer {
|
||||
self.currentItems.data.?.deinit();
|
||||
self.currentItems.data = null;
|
||||
}
|
||||
}
|
||||
errdefer {
|
||||
self.currentItems.data.?.deinit();
|
||||
self.currentItems.data = null;
|
||||
}
|
||||
|
||||
//TODO: add async
|
||||
while (location.childrenLoading) {
|
||||
std.Thread.sleep(1 * std.time.ns_per_ms);
|
||||
}
|
||||
|
||||
for (location.children.items) |item| {
|
||||
const resolvedItem = try location.item.provider.getItemByFullName(item, &.{ .skipChildInit = false }, allocator);
|
||||
const resolvedItem = location.item.provider.getItemByFullName(item, &.{ .skipChildInit = true }, allocator) catch |e| {
|
||||
//TODO: save error to container errors
|
||||
std.debug.print("error {} {s}\r\n", .{e, item.path});
|
||||
continue;
|
||||
};
|
||||
|
||||
self.currentItems.mutex.lock();
|
||||
defer self.currentItems.mutex.unlock();
|
||||
@@ -105,8 +106,6 @@ pub const Tab = struct {
|
||||
if (self.currentLocation) |c| {
|
||||
c.item.deinit();
|
||||
}
|
||||
if (self._private.currentItemsAllocator) |arena| {
|
||||
arena.deinit();
|
||||
}
|
||||
self._private.currentItemsAllocator.deinit();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user