Fix copying files to the root path

This commit is contained in:
d0k3 2016-03-14 17:22:53 +01:00
parent 1215a19c0b
commit 40ea11d778
2 changed files with 10 additions and 5 deletions

View File

@ -127,7 +127,7 @@
/ When _LFN_UNICODE is 0, this option has no effect. */
#define _FS_RPATH 1
#define _FS_RPATH 0
/* This option configures relative path feature.
/
/ 0: Disable relative path feature and remove related functions.
@ -146,7 +146,7 @@
#define _STR_VOLUME_ID 0
#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
#define _VOLUME_STRS "SDCARD","CTRNAND_S","TWLN_S","TWLP_S","CTRNAND_E","TWLN_E","TWLP_E" // <--- improve(!!!)
/* _STR_VOLUME_ID option switches string volume ID feature.
/ When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
/ number in the path name. _VOLUME_STRS defines the drive ID strings for each

View File

@ -136,8 +136,11 @@ bool PathCopyWorker(char* dest, char* orig, bool overwrite) {
bool ret = false;
if (f_stat(dest, &fno) != FR_OK) return false; // destination directory does not exist
if (!(fno.fattrib & AM_DIR)) return false; // destination is not a directory (must be at this point)
if (f_stat(dest, &fno) != FR_OK) { // is root or destination does not exist
DIR tmp_dir; // check if root
if (f_opendir(&tmp_dir, dest) != FR_OK) return false;
f_closedir(&tmp_dir);
} else if (!(fno.fattrib & AM_DIR)) return false; // destination is not a directory (must be at this point)
if (f_stat(orig, &fno) != FR_OK) return false; // origin does not exist
// build full destination path (on top of destination directory)
@ -150,9 +153,11 @@ bool PathCopyWorker(char* dest, char* orig, bool overwrite) {
// check if destination is part of or equal origin
if (strncmp(dest, orig, strnlen(orig, 255)) == 0) {
if ((dest[strnlen(orig, 255)] == '/') || (dest[strnlen(orig, 255)] == '\0'))
if ((dest[strnlen(orig, 255)] == '/') || (dest[strnlen(orig, 255)] == '\0')) {
ShowPrompt(false, "Error: Destination is part of origin");
return false;
}
}
// check if destination exists
if (!overwrite && (f_stat(dest, NULL) == FR_OK)) {