coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

`install`: Accept special files like `/dev/stdin`

Open TheDcoder opened this issue 2 years ago • 6 comments

GNU coreutils accepts special files like /dev/stdin without any issues, for e.g.:

$ echo 'foo' | install /dev/stdin test

That creates a file called test with foo\n as its contents, which isn't surprising.

However our coreutils fail with the same usage with this error:

install: cannot install '/dev/stdin' to 'test': Invalid input parameter

This issue doesn't effect cp, however it might effect other utils which haven't been tested.

TheDcoder avatar Jul 13 '23 22:07 TheDcoder

Found in the wild here:

echo 'g keyd' | install -Dm644 /dev/stdin "${pkgdir}/usr/lib/sysusers.d/${pkgname%-git}.conf"

TheDcoder avatar Jul 13 '23 22:07 TheDcoder

I checked the source code and install just uses std::fs::copy, which indeed doesn't handle that case. cp has a more complicated procedure which falls back to copying the contents. I think it might make sense to extract that procedure to uucore and share it between the two utils. Could also be fun to make it a separate crate later too, because it might be useful for other projects to have a more flexible copy function, but let's start with uucore.

tertsdiepraam avatar Jul 14 '23 11:07 tertsdiepraam

Wondering if this (moving cp code to uucore) could be a good "first step" for https://github.com/uutils/coreutils/issues/5203 ?

granquet avatar Sep 18 '23 15:09 granquet

Checked right now, works correctly. Perhaps the issue should be closed?

Javatrix avatar Aug 15 '24 18:08 Javatrix

What fixed the issue? :thinking:

TheDcoder avatar Aug 16 '24 09:08 TheDcoder

I don't know, but this issue seems to be quite old. Perhaps somebody fixed it and forgot to mark this as complete.

Javatrix avatar Aug 16 '24 11:08 Javatrix

Issue still persists apparently. The only time when it works is when I use zsh's herestring which works because zsh creates some sort of non-special temporary file I think. Piping to the command still breaks install though. I think /dev/stdin should be handled specially, kinda like how uutil's cat does it

DaringCuteSeal avatar Nov 16 '24 05:11 DaringCuteSeal

Don't hesitate to provide a patch, it should not be hard

sylvestre avatar Nov 16 '24 09:11 sylvestre

i'll try

DaringCuteSeal avatar Nov 16 '24 13:11 DaringCuteSeal

I checked the source code and install just uses std::fs::copy, which indeed doesn't handle that case. cp has a more complicated procedure which falls back to copying the contents. I think it might make sense to extract that procedure to uucore and share it between the two utils. Could also be fun to make it a separate crate later too, because it might be useful for other projects to have a more flexible copy function, but let's start with uucore.

since this also affects cp i figured that i may wanna do exactly that

DaringCuteSeal avatar Nov 17 '24 04:11 DaringCuteSeal

Fixed in https://github.com/uutils/coreutils/pull/6965

cakebaker avatar Dec 29 '24 15:12 cakebaker