Skip to content

Commit

Permalink
Support replacing files in rename for better compatibility with POS…
Browse files Browse the repository at this point in the history
…IX (#483)
  • Loading branch information
s5bug authored Apr 16, 2021
1 parent 2a9f86f commit 1f4669f
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions libctru/source/archive_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,12 +980,29 @@ 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(R_FAILED(rc) && R_DESCRIPTION(rc) == RD_ALREADY_EXISTS) {
rc = FSUSER_DeleteFile(sourceDevice->archive, fs_path_new);
if(R_FAILED(rc)) {
r->_errno = archive_translate_error(rc);
return -1;
}
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(R_FAILED(rc) && R_DESCRIPTION(rc) == RD_ALREADY_EXISTS) {
/* only overwrite empty directories */
rc = FSUSER_DeleteDirectory(sourceDevice-> archive, fs_path_new);
if(R_FAILED(rc)) {
r->_errno = archive_translate_error(rc);
return -1;
}
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

0 comments on commit 1f4669f

Please sign in to comment.