diff --git a/src/Project.zig b/src/Project.zig index 017c12c..66bacf1 100644 --- a/src/Project.zig +++ b/src/Project.zig @@ -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 }); 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) { .sym_link, .file => try self.update_mru_internal(path, mtime, row, col), 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 }); 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) { .sym_link, .file => try self.update_mru_internal(path, mtime, row, col), else => {}, @@ -2064,14 +2070,16 @@ pub fn process_git(self: *Self, parent: tp.pid_ref, m: tp.message) (OutOfMemoryE try self.loaded(parent); } 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); - 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); (try self.pending.addOne(self.allocator)).* = .{ .path = try self.allocator.dupe(u8, path), .type = file_type, .icon = file_icon, .color = file_color, - .mtime = stat.mtime, + .mtime = mtime, }; } else if (try m.match(.{ tp.any, tp.any, "workspace_files", tp.null_ })) { self.state.workspace_files = .done; diff --git a/src/buffer/Buffer.zig b/src/buffer/Buffer.zig index 2188f1d..2a0db57 100644 --- a/src/buffer/Buffer.zig +++ b/src/buffer/Buffer.zig @@ -1423,9 +1423,12 @@ pub const StoreToFileError = error{ }; pub fn store_to_existing_file_const(self: *const Self, file_path: []const u8) StoreToFileError!void { - const stat = try cwd().statFile(file_path); - var write_buffer: [4096]u8 = undefined; - var atomic = try cwd().atomicFile(file_path, .{ .mode = stat.mode, .write_buffer = &write_buffer }); + var atomic = blk: { + var write_buffer: [4096]u8 = undefined; + 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(); try self.store_to_file_const(&atomic.file_writer.interface); try atomic.finish();