Compare commits

...

3 commits

2 changed files with 18 additions and 7 deletions

View file

@ -196,7 +196,10 @@ pub fn restore_state_v1(self: *Self, data: []const u8) !void {
} }
tp.trace(tp.channel.debug, .{ "restore_state_v1", "file", path, mtime, row, col }); tp.trace(tp.channel.debug, .{ "restore_state_v1", "file", path, mtime, row, col });
self.longest_file_path = @max(self.longest_file_path, path.len); self.longest_file_path = @max(self.longest_file_path, path.len);
const stat = std.fs.cwd().statFile(path) catch continue; const stat = std.fs.cwd().statFile(path) catch {
try self.update_mru_internal(path, mtime, row, col);
continue;
};
switch (stat.kind) { switch (stat.kind) {
.sym_link, .file => try self.update_mru_internal(path, mtime, row, col), .sym_link, .file => try self.update_mru_internal(path, mtime, row, col),
else => {}, else => {},
@ -260,7 +263,10 @@ pub fn restore_state_v0(self: *Self, data: []const u8) error{
}) { }) {
tp.trace(tp.channel.debug, .{ "restore_state_v0", "file", path, mtime, row, col }); tp.trace(tp.channel.debug, .{ "restore_state_v0", "file", path, mtime, row, col });
self.longest_file_path = @max(self.longest_file_path, path.len); self.longest_file_path = @max(self.longest_file_path, path.len);
const stat = std.fs.cwd().statFile(path) catch continue; const stat = std.fs.cwd().statFile(path) catch {
try self.update_mru_internal(path, mtime, row, col);
continue;
};
switch (stat.kind) { switch (stat.kind) {
.sym_link, .file => try self.update_mru_internal(path, mtime, row, col), .sym_link, .file => try self.update_mru_internal(path, mtime, row, col),
else => {}, else => {},
@ -2064,14 +2070,16 @@ pub fn process_git(self: *Self, parent: tp.pid_ref, m: tp.message) (OutOfMemoryE
try self.loaded(parent); try self.loaded(parent);
} else if (try m.match(.{ tp.any, tp.any, "workspace_files", tp.extract(&path) })) { } else if (try m.match(.{ tp.any, tp.any, "workspace_files", tp.extract(&path) })) {
self.longest_file_path = @max(self.longest_file_path, path.len); self.longest_file_path = @max(self.longest_file_path, path.len);
const stat = std.fs.cwd().statFile(path) catch return; const mtime: i128 = blk: {
break :blk (std.fs.cwd().statFile(path) catch break :blk 0).mtime;
};
const file_type: []const u8, const file_icon: []const u8, const file_color: u24 = guess_file_type(path); const file_type: []const u8, const file_icon: []const u8, const file_color: u24 = guess_file_type(path);
(try self.pending.addOne(self.allocator)).* = .{ (try self.pending.addOne(self.allocator)).* = .{
.path = try self.allocator.dupe(u8, path), .path = try self.allocator.dupe(u8, path),
.type = file_type, .type = file_type,
.icon = file_icon, .icon = file_icon,
.color = file_color, .color = file_color,
.mtime = stat.mtime, .mtime = mtime,
}; };
} else if (try m.match(.{ tp.any, tp.any, "workspace_files", tp.null_ })) { } else if (try m.match(.{ tp.any, tp.any, "workspace_files", tp.null_ })) {
self.state.workspace_files = .done; self.state.workspace_files = .done;

View file

@ -1423,9 +1423,12 @@ pub const StoreToFileError = error{
}; };
pub fn store_to_existing_file_const(self: *const Self, file_path: []const u8) StoreToFileError!void { pub fn store_to_existing_file_const(self: *const Self, file_path: []const u8) StoreToFileError!void {
const stat = try cwd().statFile(file_path); var atomic = blk: {
var write_buffer: [4096]u8 = undefined; var write_buffer: [4096]u8 = undefined;
var atomic = try cwd().atomicFile(file_path, .{ .mode = stat.mode, .write_buffer = &write_buffer }); const stat = cwd().statFile(file_path) catch
break :blk try cwd().atomicFile(file_path, .{ .write_buffer = &write_buffer });
break :blk try cwd().atomicFile(file_path, .{ .mode = stat.mode, .write_buffer = &write_buffer });
};
defer atomic.deinit(); defer atomic.deinit();
try self.store_to_file_const(&atomic.file_writer.interface); try self.store_to_file_const(&atomic.file_writer.interface);
try atomic.finish(); try atomic.finish();