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

[BUG] Unable to remove directory if ffconfigFINDAPI_ALLOW_WILDCARDS is enabled. #66

Open
danfahrion opened this issue Apr 5, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@danfahrion
Copy link

FF_RmDir first calls FF_isDirEmpty which incorrectly states the directory is not empty.
FF_isDirEmpty calls FF_FindFirst to determine if the directory is empty. However when ffconfigFINDAPI_ALLOW_WILDCARDS is enabled the behavior of FF_FindFirst is:
" path = "\sub1\newdir" - Get the DIRENT for the newdir directory in /sub1/ if one exists."
Which then returns the entry to the directory itself rather than iterating through the directory. FF_isDirEmpty sees the entry that isn't "." or ".." and returns that is is not empty, even it if was empty, preventing it from being removed.

Reproduce on any platform with ffconfigFINDAPI_ALLOW_WILDCARDS enabled, create an empty directory and try to remove it with FF_RmDir.

Expect Directory is removed.
Instead returns pdFREERTOS_ERRNO_ENOTEMPTY even though directory is empty.

In my code I added this hack where FF_isDirEmpty calls FF_FindFirst to make it work, but there is probably a better solution, as this is really a side effect of the odd wildcard handling in FF_FindFirst:

#if ( ffconfigFINDAPI_ALLOW_WILDCARDS != 0 )
static char tmppath[ffconfigMAX_FILENAME];
// If ffconfigFINDAPI_ALLOW_WILDCARDS is enabled, FF_FindFirst will return the directory entry itself
// rather than the contents unless we append a '/' to the path. Finding the directory entry itself makes
// this function return that the directory is not empty even when it is in fact empty.
strlcpy(tmppath, pcPath, ffconfigMAX_FILENAME);
strlcat(tmppath, "/", ffconfigMAX_FILENAME);
xError = FF_FindFirst(pxIOManager, &xDirEntry, tmppath);
#else
xError = FF_FindFirst(pxIOManager, &xDirEntry, pcPath);
#endif

@danfahrion danfahrion added the bug Something isn't working label Apr 5, 2024
@Skptak
Copy link
Member

Skptak commented Apr 6, 2024

Hey @danfahrion, thanks for submitting this bug report. If you think that your call to FF_FindFirst is something that solves this issue would you mind raising a PR with those changes? The team can then evaluate if we consider it a viable solution, or if a better one should be investigated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants