Skip to content

install: fix error messages to align with GNU for cannot-stat and failed-to-remove.#9987

Open
sgmarz wants to merge 8 commits intouutils:mainfrom
sgmarz:install_err_remove_nostat
Open

install: fix error messages to align with GNU for cannot-stat and failed-to-remove.#9987
sgmarz wants to merge 8 commits intouutils:mainfrom
sgmarz:install_err_remove_nostat

Conversation

@sgmarz
Copy link
Copy Markdown

@sgmarz sgmarz commented Jan 2, 2026

Fixes #9934

This PR will update the failed-to-remove error message to better align with GNU coreutils. Furthermore, it adds "cannot stat" for when looking for a file to see if it exists fails. This can fail for myriad of reasons, including permission denied.

Test: original issue request

$ uu-install /dev/null /dev/full
install: failed to remove existing file '/dev/full': Permission denied (os error 13)
$ gnu-install /dev/null /dev/full
install: cannot remove '/dev/full': Permission denied

The original issue was due to the way Rust's standard library calculates is_file. It only checks for regular files to be file, but on a UNIX configuration, the files could include block and character devices as well as a FIFO device. This patch now checks the metadata to check specifically for block, character, and FIFO devices on UNIX configurations. If the configuration is not UNIX, it reverts to the original behavior.

Test: cannot stat due to permission error

$ uu-install /dev/null /root/file
install: cannot stat '/root/file': Permission denied (os error 13)
$ gnu-install /dev/null /root/file
install: cannot stat '/root/file': Permission denied

The issue here was due to the way the main branch does remove_file. Since no checks are done before this function call, we get too granular of an error: was it due to not found or not? In this patch, there is an additional check using Rust's standard try_exists. This will tell us if the actual calculation of a file existing failed.

@sylvestre
Copy link
Copy Markdown
Contributor

lot of jobs failing

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 3, 2026

GNU testsuite comparison:

Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 4, 2026

GNU testsuite comparison:

Congrats! The gnu test tests/printf/printf-surprise is now passing!

@sylvestre
Copy link
Copy Markdown
Contributor

please add tests to verify the errors & messages
thanks

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 7, 2026

GNU testsuite comparison:

GNU test failed: tests/shuf/shuf-reservoir. tests/shuf/shuf-reservoir is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/sort/sort-stale-thread-mem. tests/sort/sort-stale-thread-mem is passing on 'main'. Maybe you have to rebase?

@sylvestre
Copy link
Copy Markdown
Contributor

i think the rebase went wrong

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 7, 2026

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@ChrisDryden ChrisDryden force-pushed the install_err_remove_nostat branch from 9812121 to acda29c Compare February 14, 2026 17:26
@ChrisDryden
Copy link
Copy Markdown
Collaborator

Fixed the rebase

assert_eq!(0o40_200_u32, at.metadata(target_dir).permissions().mode());
}

#[test]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The files that are being used to test do not exist on macos

Comment thread src/uu/install/src/install.rs Outdated
// and it will give an incorrect error message. However, if we check to
// see if the file exists, and it can't even be checked, this means we
// don't have permission to access the file, so we should return an error.
if let Err(to_stat) = to.try_exists() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theres the pattern .map_err_contect that wraps these into errors in a simpler way thats used in the project that would make this much cleaner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

install /dev/null /dev/full has wrong error message

3 participants