`install`: Accept special files like `/dev/stdin`
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.
Found in the wild here:
echo 'g keyd' | install -Dm644 /dev/stdin "${pkgdir}/usr/lib/sysusers.d/${pkgname%-git}.conf"
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.
Wondering if this (moving cp code to uucore) could be a good "first step" for https://github.com/uutils/coreutils/issues/5203 ?
Checked right now, works correctly. Perhaps the issue should be closed?
What fixed the issue? :thinking:
I don't know, but this issue seems to be quite old. Perhaps somebody fixed it and forgot to mark this as complete.
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
Don't hesitate to provide a patch, it should not be hard
i'll try
I checked the source code and
installjust usesstd::fs::copy, which indeed doesn't handle that case.cphas a more complicated procedure which falls back to copying the contents. I think it might make sense to extract that procedure touucoreand 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 flexiblecopyfunction, but let's start withuucore.
since this also affects cp i figured that i may wanna do exactly that
Fixed in https://github.com/uutils/coreutils/pull/6965