Oh, another strange issue:
Dir deletion after dir creation works great on USB drive. My routine failed on deleting a newly created dir on internal flash.
Why? Fount that on creating a dir on internal flash it creates a . subdir in that new dir. Did not check, but probably also a .. subdir, just like are present in the root.
I filter them out in dir parsing, so first was not understanding why my 'check if dir is empty' routine failed. But see it if I print debug info:
See the 10 . on the third line: 10 is the attribute in hex, so DIR, . is the name.
Is this a bug? Or something I have to live with and account for by also deleting the . and .. subdirs on dir delete?
Or is there any way to force a recursive delete?
Edit: Found that actually if I comment out my 'check if dir is empty' the dir delete on internal flash actually does work. While it fails as it should if I place actual files in. So for the internal storage filesystem, a dir with those . and .. subdirs is actually considered empty.
So workaround: I will not only check if dir is empty for USB, and just let it fail with OS error if internal storage dir is not empty on delete attempt.
Or is there a better way, working on both USB as internal flash, to check if dir is empty than this?
Code: Select all
// Check if dir is empty
// First: open dir
dir = opendir(pathbuffer);
if (!dir)
{
// Exit if dir can not be opened
menu_fileerrormessage();
return;
}
// Then: try to read first entry
file = readdir(dir);
if (file->d_name[0] != 0)
{
// Exit if dir is not empty
menu_messagepopup("Directory is not empty.");
closedir(dir);
return;
}
// Close dir
closedir(dir);
Full code and latest build still here. Needs newer firmware build than on the official release yet, latest Raxiss build will work. Do not yet check for FW version (also because uname gives the same 0.2.5 version also for the newest Raxiss build), assume not implemented opp codes just do nothing? Or give OS error?
https://github.com/xahmol/locifilemanager