Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support replacing files in rename for better compatibility with POSIX #483

Merged
merged 3 commits into from
Apr 16, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions libctru/source/archive_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,12 +980,23 @@ archive_rename(struct _reent *r,
}

rc = FSUSER_RenameFile(sourceDevice->archive, fs_path_old, sourceDevice->archive, fs_path_new);
if(R_SUCCEEDED(rc))
return 0;
/* if the file at the target destination exists, overwrite it */
if(rc == 0xC82044BE) {
WinterMute marked this conversation as resolved.
Show resolved Hide resolved
rc = FSUSER_DeleteFile(sourceDevice->archive, fs_path_new);
if(R_FAILED(rc)) return -1;
WinterMute marked this conversation as resolved.
Show resolved Hide resolved
rc = FSUSER_RenameFile(sourceDevice->archive, fs_path_old, sourceDevice->archive, fs_path_new);
if(R_SUCCEEDED(rc)) return 0;
} else if(R_SUCCEEDED(rc)) return 0;

rc = FSUSER_RenameDirectory(sourceDevice->archive, fs_path_old, sourceDevice->archive, fs_path_new);
if(R_SUCCEEDED(rc))
return 0;
/* if the directory at the target destination exists, overwrite it */
if(rc == 0xC82044BE) {
WinterMute marked this conversation as resolved.
Show resolved Hide resolved
/* only overwrite empty directories */
rc = FSUSER_DeleteDirectory(sourceDevice-> archive, fs_path_new);
if(R_FAILED(rc)) return -1;
WinterMute marked this conversation as resolved.
Show resolved Hide resolved
rc = FSUSER_RenameDirectory(sourceDevice->archive, fs_path_old, sourceDevice->archive, fs_path_new);
if(R_SUCCEEDED(rc)) return 0;
} else if(R_SUCCEEDED(rc)) return 0;

r->_errno = archive_translate_error(rc);
return -1;
Expand Down