On 19/4/19 6:42 am, Nicolas Schier wrote:
Control: severity -1 wishlist
Control: tag -1 wontfix

On Tue, Jan 22, 2019 at 09:40:20AM +1100, Hamish Moffatt wrote:
[...]
sponge preserves file permissions (as mentioned in the man page), but
not the file ownership.

This is different from shell redirections in bash, which do preserve
ownership.
yes, you're right.  As 'sponge' is not a shell redirect, and it is not
designed to emulate one, it behaves more like 'tee' than like a shell
redirection.  I do understand that preserving the owner might be a nice
feature, but I think this could work well only if 'sponge' is called
with superuser capabilities (or if installed with suid-bit set).

Why do you think that sponge ought to preserve the owner?  Did the man
page induce that somehow?


I only expect it to preserve the ownership when you run it as root, on a file which doesn't belong to root.

tee preserves the file ownership in this case, just as shell redirections do. sponge does not.


With tee:

# id
uid=0(root) gid=0(root) groups=0(root)


# ls -l foo
-rw-r--r-- 1 hamish hamish 257 Apr 23 09:52 foo
# echo hi | tee foo
hi
# ls -l foo
-rw-r--r-- 1 hamish hamish 3 Apr 23 09:53 foo


But with sponge:

# echo hi | sponge foo
# ls -l foo
-rw-r--r-- 1 root root 3 Apr 23 09:53 foo


tee is doing this automatically because it truncates the original file. sponge is copying the permissions from the original to the new file before replacing the original. It could also copy the owner, if running as root.


Hamish

Reply via email to