mkdir: do not ignore EEXIST on non-recursive creation - #13986
Open
l46983284-cpu wants to merge 1 commit into
Open
mkdir: do not ignore EEXIST on non-recursive creation#13986l46983284-cpu wants to merge 1 commit into
l46983284-cpu wants to merge 1 commit into
Conversation
Fixes uutils#13970 Signed-off-by: Alex Chen <l46983284@gmail.com>
|
GNU testsuite comparison: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13970.
mkdirwithout-pincorrectly swallowsEEXISTwhen the target path already exists as a directory. Increate_single_dir, the error branchErr(_) if path.is_dir()returnsOk(())unconditionally, without checking whether recursive (-p) mode was requested.This is a logic bug: a non-recursive
mkdiron an existing directory must fail per POSIX, but currently exits 0. Under concurrent invocation, this also allows multiple racing processes to all "succeed" in creating the same directory.Fix: require
config.recursive || is_parentbefore allowing theEEXIST→Ok(())fallback. This matches GNU mkdir behavior and the existing test expectations.Regression tests:
test_mkdir_concurrent_creation: concurrentmkdir -pon the same path — all processes must succeed (valid for-p).test_mkdir_concurrent_non_recursive: concurrentmkdirwithout-pon the same path — exactly one process must win per round.Verified on bare-metal Linux and in a sandboxed environment: 500 concurrent rounds on main showed double-wins (both processes exiting 0), while this branch showed 0 double-wins. All existing tests pass.