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

Fix return value of lfs_rename() #917

Merged
merged 2 commits into from
Jan 19, 2024
Merged

Fix return value of lfs_rename() #917

merged 2 commits into from
Jan 19, 2024

Conversation

tomscii
Copy link
Contributor

@tomscii tomscii commented Jan 3, 2024

When lfs_rename() is called trying to rename (move) a file to an existing directory, LFS_ERR_ISDIR is (correctly) returned. However, in the opposite case, if one tries to rename (move) a directory to a path currently occupied by a regular file, LFS_ERR_NOTDIR should be returned (since the error is that the destination is NOT a directory), but in reality, LFS_ERR_ISDIR is returned in this case as well.

This commit fixes the code so that in the latter case, LFS_ERR_NOTDIR is returned.

@geky-bot
Copy link
Collaborator

geky-bot commented Jan 3, 2024

Tests passed ✓, Code: 16836 B (+0.0%), Stack: 1448 B (+0.0%), Structs: 800 B (+0.0%)
Code Stack Structs Coverage
Default 16836 B (+0.0%) 1448 B (+0.0%) 800 B (+0.0%) Lines 2357/2535 lines (-0.1%)
Readonly 6130 B (+0.0%) 448 B (+0.0%) 800 B (+0.0%) Branches 1202/1530 branches (-0.1%)
Threadsafe 17704 B (+0.0%) 1448 B (+0.0%) 808 B (+0.0%) Benchmarks
Multiversion 16900 B (+0.0%) 1448 B (+0.0%) 804 B (+0.0%) Readed 29369693876 B (+0.0%)
Migrate 18516 B (+0.0%) 1752 B (+0.0%) 804 B (+0.0%) Proged 1482874766 B (+0.0%)
Error-asserts 17492 B (+0.0%) 1440 B (+0.0%) 800 B (+0.0%) Erased 1568888832 B (+0.0%)

@geky
Copy link
Member

geky commented Jan 16, 2024

Hi @tomscii, thanks for this. This does look more correct in terms of following POSIX.

The only concern is if this will break any existing code. Code may be relying on LFS_ERR_NOTDIR for both cases.

I'll plan on bringing this in on the next minor release. If it's an issue, we'll learn, otherwise I think the strategy may be to allow error codes to change to match POSIX on minor releases.

@geky geky added needs minor version new functionality only allowed in minor versions needs test all fixes need test coverage to prevent regression enhancement labels Jan 16, 2024
@geky geky added next minor and removed needs minor version new functionality only allowed in minor versions labels Jan 17, 2024
@geky geky modified the milestones: v2.8, v2.9 Jan 17, 2024
tomscii and others added 2 commits January 17, 2024 00:06
When lfs_rename() is called trying to rename (move) a file to an
existing directory, LFS_ERR_ISDIR is (correctly) returned. However, in
the opposite case, if one tries to rename (move) a directory to a path
currently occupied by a regular file, LFS_ERR_NOTDIR should be
returned (since the error is that the destination is NOT a directory),
but in reality, LFS_ERR_ISDIR is returned in this case as well.

This commit fixes the code so that in the latter case, LFS_ERR_NOTDIR
is returned.
@geky
Copy link
Member

geky commented Jan 17, 2024

I've gone ahead and updating this PR for two minor reasons:

  1. Updated to match style, mainly double-indention (8-spaces) in expressions. I realize this isn't really documented anywhere.
  2. Added tests to ensure that the rename type mismatch returns this error as expected.

Let me know if anything looks concerning.

@geky-bot
Copy link
Collaborator

Tests passed ✓, Code: 16836 B (+0.0%), Stack: 1448 B (+0.0%), Structs: 800 B (+0.0%)
Code Stack Structs Coverage
Default 16836 B (+0.0%) 1448 B (+0.0%) 800 B (+0.0%) Lines 2359/2535 lines (+0.0%)
Readonly 6130 B (+0.0%) 448 B (+0.0%) 800 B (+0.0%) Branches 1205/1530 branches (+0.1%)
Threadsafe 17704 B (+0.0%) 1448 B (+0.0%) 808 B (+0.0%) Benchmarks
Multiversion 16900 B (+0.0%) 1448 B (+0.0%) 804 B (+0.0%) Readed 29369693876 B (+0.0%)
Migrate 18516 B (+0.0%) 1752 B (+0.0%) 804 B (+0.0%) Proged 1482874766 B (+0.0%)
Error-asserts 17492 B (+0.0%) 1440 B (+0.0%) 800 B (+0.0%) Erased 1568888832 B (+0.0%)

@tomscii
Copy link
Contributor Author

tomscii commented Jan 17, 2024

@geky Looks great, thank you!

@geky geky removed the needs test all fixes need test coverage to prevent regression label Jan 19, 2024
@geky geky changed the base branch from master to devel January 19, 2024 18:16
@geky geky merged commit ceb17a0 into littlefs-project:devel Jan 19, 2024
93 checks passed
@geky geky mentioned this pull request Jan 19, 2024
@geky
Copy link
Member

geky commented Jan 23, 2024

This is on master now, thanks for the PR!

@tomscii
Copy link
Contributor Author

tomscii commented Jan 23, 2024

This is on master now, thanks for the PR!

Excellent! Thanks for all your hard work maintaining LittleFS!

@tomscii tomscii deleted the fix_return_value_of_lfs_rename branch January 23, 2024 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants