Working delete routines (needs testing, though)

This commit is contained in:
d0k3 2016-03-02 14:15:29 +01:00
parent 7ab86c87a3
commit 2a53ee0a5b

View File

@ -218,38 +218,35 @@ bool PathCopy(const char* destdir, const char* orig) {
bool PathDeleteWorker(char* fpath) { bool PathDeleteWorker(char* fpath) {
FILINFO fno; FILINFO fno;
bool ret = true;
// the deletion process takes place here // this code handles directory content deletion
if (f_stat(fpath, &fno) != FR_OK) return false; // fpath does not exist if (f_stat(fpath, &fno) != FR_OK) return false; // fpath does not exist
if (fno.fattrib & AM_DIR) { // process folder contents if (fno.fattrib & AM_DIR) { // process folder contents
DIR pdir; DIR pdir;
char* fname = fpath + strnlen(fpath, 256); char* fname = fpath + strnlen(fpath, 255);
if (f_opendir(&pdir, fpath) != FR_OK) if (f_opendir(&pdir, fpath) != FR_OK)
return false; return false;
*(fname++) = '/'; *(fname++) = '/';
fno.lfname = fname; fno.lfname = fname;
fno.lfsize = 256 - (fname - fpath); fno.lfsize = fpath + 255 - fname;
while (f_readdir(&pdir, &fno) == FR_OK) { while (f_readdir(&pdir, &fno) == FR_OK) {
if ((strncmp(fno.fname, ".", 2) == 0) || (strncmp(fno.fname, "..", 3) == 0)) if ((strncmp(fno.fname, ".", 2) == 0) || (strncmp(fno.fname, "..", 3) == 0))
continue; // filter out virtual entries continue; // filter out virtual entries
if (fname[0] == 0) if (fname[0] == 0)
strncpy(fname, fno.fname, 256 - (fname - fpath)); strncpy(fname, fno.fname, fpath + 255 - fname);
if (fno.fname[0] == 0) { if (fno.fname[0] == 0) {
break; break;
} else if (!PathDeleteWorker(fpath)) { } else { // return value won't matter
ret = false; PathDeleteWorker(fpath);
} }
} }
f_closedir(&pdir); f_closedir(&pdir);
*(--fname) = '\0'; *(--fname) = '\0';
} else { // processing files...
ret = (f_unlink(fpath) == FR_OK);
} }
return ret; return (f_unlink(fpath) == FR_OK);
} }
bool PathDelete(const char* path) { bool PathDelete(const char* path) {