FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [January 2016 Threads] +FAT: ff_findfirst, ff_findnext, and ff_removePosted by pascal-vehigy on January 27, 2016 To whom it may concern,
I am cycling through all files in a given directory, processing them, and afterwards deleting them. Is it possible, that the ff_findnext function does not work if a file in the current working directory is being deleted in between iterations?
My sequence of events is something like that:
1. change working directory with ffchdir
2. allocate some memory and get the pointer for the FFFindDatat struct
3. RetVal = fffindfirst( "", pxFindStruct )
4. if RetVal != 0 -> abort
5. if it is a dot (. or ..) entry or another directory skip it
6. else open the file ffopen(pxFindStruct->pcFileName, "r"), send it via TCP, finally ffclose(...)
7. if the TCP server on the other end responded positively, delete the file: ffremove( pxFindStruct->pcFileName )
8. RetVal = fffindnext( pxFindStruct )
9. loop back to 4 while RetVal == 0
Am I missing something? Does the FindStruct get messed up because I am deleting files while I iterate through them?
If there is only one file in the directory, it works perfectly fine. If a few files have been accumulated, the first one is being sent and removed, but then ff_findnext breaks the loop. However, I can access the very same FAT through FTP and fetch the remainng files. They are perfectly readable, the size and content is exactly as expected.
Thanks for any hints on what might be going on here.
Sincerely,
Pascal
+FAT: ff_findfirst, ff_findnext, and ff_removePosted by rtel on January 27, 2016 Hi Pascal, thank you for your valuable description. We will check it out and report back here.
+FAT: ff_findfirst, ff_findnext, and ff_removePosted by heinbali01 on January 27, 2016 Hi Pascal,
I'm not sure how W32 or Linux will respond if you try to do the same: delete the current file while iterating through a directory.
Here is a solution, although it will use ffconfigMAX_FILENAME bytes on the stack:
~~~~~
BaseTypet xFindResult = fffindfirst( pcPath, &xFindData );
while( xFindResult >= 0 )
{
char pcFileName[ ffconfigMAX_FILENAME ];
snprintf( pcFileName, sizeof( pcFileName ),
xFindData.xDirectoryEntry.pcFileName );
/* Move to the next file before the
current entry gets deleted. */
xFindResult = ff_findnext( &xFindData );
SendFile( pcFileName );
ff_remove( pcFileName );
}
~~~~~
PS. If you need to access all properties of "the current file", you would have to make a copy of xFindData.xDirectoryEntry which has the type FF_DirEnt_t .
Regards.
+FAT: ff_findfirst, ff_findnext, and ff_removePosted by pascal-vehigy on January 27, 2016 Hi Hein,
thank you for the quick reply. Yep, your way does make more sense, I guess I was too greedy with stack usage. But in my case the files, which obviously are a backlog as you undoubtetly have figured, have a fixed naming scheme, so it is no problem to buffer the "current" filename on the stack.
I haven't actually gotten to try it out yet, but I am sure this approach will work. Otherwise I will be posting back.
Have a nice evening (or whatever time of day it is for you),
Pascal
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|