install: don't trim the root away when creating leading dirs - #13998
Open
MsfPablo wants to merge 1 commit into
Open
install: don't trim the root away when creating leading dirs#13998MsfPablo wants to merge 1 commit into
MsfPablo wants to merge 1 commit into
Conversation
With -D and a single-component absolute destination, the parent to create is /. The trailing-separator trimming ran that down to an empty path, which exists() reports as absent, so install tried to create it, failed with ENOENT, and left the destination unwritten. Stop trimming at the root and move the logic into a helper so the boundary can be tested directly. Fixes uutils#13232
|
GNU testsuite comparison: |
Contributor
|
Please add a test in test_install.rs |
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 #13232.
For
install -D src /dest, the parent to create is/. The trailing-separator loop stripped separators unconditionally, and since/is nothing but a separator it came out as an empty path."".exists()is false, so install decided the parent was missing, tried to create it, and failed:The loop now stops while one separator is left.
/stays/, which exists and is a directory, so the copy proceeds — matching the documented-Dbehaviour, where the only leading component of/fileis a root that already exists.I pulled the trimming into a
trim_trailing_separatorshelper so the root boundary is unit-testable, and switched its byte conversion touucore::os_str_from_bytes; the inline version usedOsStrExt::from_bytes, which is behind a#[cfg(unix)]import in this file.Verified against the reproducer: before, the chmod ENOENT above; after, install gets far enough to report the real reason for the destination being unwritable, and the source is left alone.
Tests: unit tests for the helper, covering
/,//, ordinary trailing slashes, and the no-op cases. The end-to-end case needs a writable/, so I did not add an integration test for it — the existing 104 install tests still pass.