Uh oh!
There was an error while loading. Please reload this page.
Add rename to std.fs API - #6354
Conversation
Made the directory rename tests get skipped on Windows for now, the fix there ended up being much more complex than anticipated so I split it into its own issue: #6364 |
How about |
andrewrk
left a comment
There was a problem hiding this comment.
Nice work! I have 1 requested change, and 1 optional suggestion for naming, and then this is good to go.
Uh oh!
There was an error while loading. Please reload this page.
- Moves fs.rename functions to fs.renameAbsolute to match other functions outside of fs.Dir - Adds fs.Dir.rename that takes two paths relative to the given Dir - Adds fs.rename that takes two separate Dir's that the given paths are relative to (for renaming across directories without having to make the second path relative to a single directory) - Fixes FileNotFound error return in std.os.windows.MoveFileExW - Returns error.RenameAcrossMountPoints from renameatW + Matches the RenameAcrossMountPoints error return in renameatWasi/renameatZ
squeek502
commented
Sep 17, 2020
Done + squashed. One other implementation I thought of, but it might be somewhat messy (especially with the Z/W variants), would be to have only struct {
dir: ?Dir=null,
path: []constu8,
}Usage: dir.rename("old_file", .{ .path="new_file" });
dir.rename("old_file", .{ .dir=other_dir, .path="new_file" });(if |
andrewrk
commented
Sep 17, 2020
I'm not against that but I would personally prefer the differently named functions for this case. Thanks for this PR, std.fs just got much cleaner! |
Closes#6344
Notes:
There is likely a better name or API forDir.renameAt. I couldn't really come up with anything, though (renameElsewhere?renameTransfer?renameTo?).The tests are currently failing on Windows.EDIT: Split the Windows rename failure to its own issue: #6364renameAbsoluteandDir.renamedo not allow renaming directories.renameAbsoluteusesMOVEFILE_REPLACE_EXISTINGwhich "cannot be used if lpNewFileName or lpExistingFileName names a directory."Dir.renameusesOpenFilewhich fails witherror.IsDir