地圖 (Jido) is a lightweight Unix TUI file explorer designed for speed and simplicity.

fix: Undoing a delete/rename wont overwrite an item with the same name now

+46 -7
+44 -6
src/event_handlers.zig
··· 275 275 defer app.alloc.free(a.new); 276 276 defer app.alloc.free(a.old); 277 277 278 - // TODO: Will overwrite an item if it has the same name. 279 - if (app.directories.dir.rename(a.new, a.old)) { 278 + var had_duplicate = false; 279 + 280 + // Handle if item with same name already exists. 281 + var new_path_buf: [std.fs.max_path_bytes]u8 = undefined; 282 + const new_path = if (environment.fileExists(app.directories.dir, a.old)) lbl: { 283 + const extension = std.fs.path.extension(a.old); 284 + had_duplicate = true; 285 + break :lbl try std.fmt.bufPrint( 286 + &new_path_buf, 287 + "{s}-{s}{s}", 288 + .{ a.old[0 .. a.old.len - extension.len], zuid.new.v4(), extension }, 289 + ); 290 + } else lbl: { 291 + break :lbl a.old; 292 + }; 293 + 294 + if (app.directories.dir.rename(a.new, new_path)) { 280 295 app.directories.clearEntries(); 281 296 const fuzzy = inputToSlice(app); 282 297 app.directories.populateEntries(fuzzy) catch |err| { ··· 285 300 else => try app.notification.writeErr(.UnknownError), 286 301 } 287 302 }; 288 - try app.notification.writeInfo(.RestoredDelete); 303 + if (had_duplicate) { 304 + try app.notification.writeWarn(.DuplicateFileOnUndo); 305 + } else { 306 + try app.notification.writeInfo(.RestoredDelete); 307 + } 289 308 } else |_| { 290 309 try app.notification.writeErr(.UnableToUndo); 291 310 } ··· 294 313 defer app.alloc.free(a.new); 295 314 defer app.alloc.free(a.old); 296 315 297 - // TODO: Will overwrite an item if it has the same name. 298 - if (app.directories.dir.rename(a.new, a.old)) { 316 + var had_duplicate = false; 317 + 318 + // Handle if item with same name already exists. 319 + var new_path_buf: [std.fs.max_path_bytes]u8 = undefined; 320 + const new_path = if (environment.fileExists(app.directories.dir, a.old)) lbl: { 321 + const extension = std.fs.path.extension(a.old); 322 + had_duplicate = true; 323 + break :lbl try std.fmt.bufPrint( 324 + &new_path_buf, 325 + "{s}-{s}{s}", 326 + .{ a.old[0 .. a.old.len - extension.len], zuid.new.v4(), extension }, 327 + ); 328 + } else lbl: { 329 + break :lbl a.old; 330 + }; 331 + 332 + if (app.directories.dir.rename(a.new, new_path)) { 299 333 app.directories.clearEntries(); 300 334 const fuzzy = inputToSlice(app); 301 335 app.directories.populateEntries(fuzzy) catch |err| { ··· 304 338 else => try app.notification.writeErr(.UnknownError), 305 339 } 306 340 }; 307 - try app.notification.writeInfo(.RestoredRename); 341 + if (had_duplicate) { 342 + try app.notification.writeWarn(.DuplicateFileOnUndo); 343 + } else { 344 + try app.notification.writeInfo(.RestoredRename); 345 + } 308 346 } else |_| { 309 347 try app.notification.writeErr(.UnableToUndo); 310 348 }
+2 -1
src/notification.zig
··· 45 45 ConfigReloaded, 46 46 }; 47 47 48 - const Warn = enum { DeprecatedConfigPath }; 48 + const Warn = enum { DeprecatedConfigPath, DuplicateFileOnUndo }; 49 49 50 50 buf: [1024]u8 = undefined, 51 51 style: Style = Style.info, ··· 106 106 pub fn writeWarn(self: *Self, warning: Warn) !void { 107 107 try switch (warning) { 108 108 .DeprecatedConfigPath => self.write("You are using a deprecated config path. Please move your config to either `$XDG_CONFIG_HOME/jido` or `$HOME/.jido`", .warn), 109 + .DuplicateFileOnUndo => self.write("A file with the same name already exists. A unique identifier has been appending to the duplicated item.", .warn), 109 110 }; 110 111 } 111 112