-
Notifications
You must be signed in to change notification settings - Fork 51
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
Change the FF_MakeNameCompliant behavior #63
Conversation
@togrue Thanks for your contribution. To get this merged, could you run look at the build failure and address it? |
/bot run formatting |
Invalid path characters cause now an error. (FF_ERR_FILE_INVALID_PATH if a file should be created and FF_ERR_DIR_INVALID_PATH for directories)
21c933c
to
61baf4e
Compare
Fixed the indentation. And also removed the superfluous (== pdTrue) in the if condition.
Sorry for the force-push, i thought i can modify my fork, without changing the pull-request. |
The happy code path is now located in the else branch which improves locality of the error handling.
One moment please, I am working on it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You chose for a different approach than I would have done. But yours is good too: you just refuse to process an invalid file name at the lowest level: at FF_CreateDirent()
.
I approve this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You wrote:
What about the case of the first filename character being '\xE5'?
The character has to be remapped to 0x05 to have no collision with the file deleted marker (which is 0xE5).
My tests showed that, filenames starting with '\xE5' still result in duplicated file-entries.
Yes, it escaped from my attention.
If we want to keep this feature, it must be checked in 3 functions:
FF_MkDir()
FF_Move()
FF_CreateFile()
And then we can as well have FF_MakeNameCompliant()
return void, as it used to do. And preserve the same behaviour as before.
Hi @togrue, I worked out a different approach, please see this attachment:
That avoids that FAT changes are made and removed, in case Also it repairs this loop: #if ( ffconfigUNICODE_UTF16_SUPPORT != 0 )
- for( index = 0; index < ( BaseType_t ) sizeof( forbiddenChars ); index++ )
+ for( index = 0; index < ( BaseType_t ) ( sizeof( forbiddenChars ) / sizeof ( forbiddenChars[ 0 ] ) ); index++ ) Without that the UTF16 version would not be correct. |
These changes were made by hitibosch. They move the name check upward in the call-hierarchy.
The previously used pcPath contained slashes. This lead to an error, because slashes are invalid Dir/Filename characters.
The function does only perform checks now.
It looks good, thank you. I am testing all changes when using |
The last version of Please have a look at this version of The tests with |
This change was made by hitibosch. I added just a comment.
Is there a testsuite, or does everyone have to rewrite all tests? I have a failing testcase with |
One more proposal for ff_file.c: - if( uxIndex == 0U )
- {
- /* Give the directory part a minimum
- * length of 1, to get '/' at least. */
- uxIndex = 1U;
- }
/* Copy the base name of the destination file. */
STRNCPY( xMyFile.pcFileName, ( szDestinationFile + uxIndex + 1 ), ffconfigMAX_FILENAME - 1 );
xMyFile.pcFileName[ ffconfigMAX_FILENAME - 1 ] = 0;
/* Now check if the target base name is compliant. */
if( FF_IsNameCompliant( xMyFile.pcFileName ) == pdFALSE )
{
xError = FF_createERR( FF_ERR_FILE_INVALID_PATH, FF_MOVE );
}
+ if( uxIndex == 0U )
+ {
+ /* Give the directory part a minimum
+ * length of 1, to get '/' at least. */
+ uxIndex = 1U;
+ } @togrue wrote:
Yes there are, for instance ff_stdio_tests_with_cwd.c. Another good test that I often do is FTP copying the entire repo of Linux from a laptop to the DUT and copy it back. Here you find the tests that I ran today: |
6244ea4
to
922b526
Compare
The first character of the destination filename was omitted when a file in the root directory was supplied. This change was made by hitibosch.
The error variable could get accessed before initialization.
922b526
to
174fd46
Compare
Using uncrustify v 0.67 And the uncrustify config from the FreeRTOS main project.
@togrue, you wrote:
Have you re-tested this after the last change? |
I used too long filenames without enabling LFN support. |
I must admit that I have LFN enabled in all of my projects that use +FAT. Another option to re-test would be Unicode/UTF16. |
Can anybody please have a look to get this PR merged? Thanks, Hein |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To summarise the PR: when an application wants to create a file with illegal characters, the file or directory will not be created.
In the current version, the illegal characters are being replaced with underscores, which was not a good idea.
Create "file:01.txt"
results in "file_01.txt"
.
But when you want to updated "file:01.txt"
, the fill will not be found and a second instance is created.
So thank you @togrue for this PR. ONce again I approve it.
Description
This changes the behavior of the FF_CreateDirent function to return an error in case of an invalid path.
Filenames with the first character of 0xE5 are still modified. (Which might have some issues. TODO)
Note: Invalid directory paths and invalid file paths now result in two different FreeRTOS+ return values. Is this the intended behavior or should only one error code be used?
FF_MakeNameCompliant returns a boolean and not an error-code, because the function
would need an additional parameter to select the right error code (FF_ERR_DIR_INVALID_PATH or FF_ERR_FILE_INVALID_PATH).
Test Steps
A invalid filepath "test:file.txt" resulted in setting the FF_ERR_FILE_INVALID_PATH. (Tested through breakpoint in prvFFErrorToErrno).
Todo:
Checklist:
Related Issue
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.