You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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.
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
The text was updated successfully, but these errors were encountered: