coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: chown: option to avoid unnecessary writes


From: Pádraig Brady
Subject: Re: chown: option to avoid unnecessary writes
Date: Sun, 29 Sep 2024 11:11:15 +0100
User-agent: Mozilla Thunderbird Beta

On 29/09/2024 06:48, Patrick Häcker wrote:
Hi,

currently chown always seems to do a chown syscall, even if the requested
user:group pair is identical to the file's user:group pair. This is especially
the case when doing a recursive run.

While this might be faster than checking whether the syscall is needed in some
cases and there might be use cases where the syscall should always be done,
there are certainly use cases to avoid the syscalls when unnecessary (see e.g.
https://github.com/sharkdp/fd/issues/1087 or https://askubuntu.com/q/1151431).

This check can be implemented in a wrapper around chown, but reinventing the
wheel in each wrapper does not seem to be the optimum solution besides making
simple "chown -R" calls more complicated than necessary.

Therefore, I propose to add an option to chown which only does the chown
syscall if the user and/or the group will change.

This would avoid ctime changes for files where the metadata really is unchanged
and would reduce writes on storage where writes are more expensive than reads.

This might be useful.
We already support --from, so I suppose we could support --from-different.
This would be susceptible to TOCTOU races just like --from.

Note there was a similar proposal for chmod discussed at:
https://lists.gnu.org/archive/html/bug-coreutils/2010-01/msg00303.html

cheers,
Pádraig



reply via email to

[Prev in Thread] Current Thread [Next in Thread]