bug#79488: [RFE] Enhancement idea : Better Handling of File Permission with CHMOD Command

Martin D Kealey <[email protected]>
Newsgroups gmane.comp.gnu.core-utils.bugs
Message-ID <CAN_U6MUUhVs0hxtVOVHRb9maqpo8tm7GZ1JOwgBLOCasW4pW-w@mail.gmail.com>
On Thu, 25 Sept 2025 at 03:01, Andreas Schwab <[email protected]> wrote:

> $ chmod-t() { local m=$(stat -c %a "$2"); chmod "$1" "$2"; sleep ${3}m;
> chmod $m "$2"; }
>
*[...]*

> $ chmod-t 777 myfile.txt 30 &


Yes but what about:

$ chmod-t u+w myfile.txt 30 & [ -w myfile.txt ] || die 'Race condition
while checking that chmod u+w worked'

But even if that's fixed by putting the '&' inside the function, there
remains a more general problem:

$ chmod-t() { local m=$(stat -c %a "$2"); chmod "$1" "$2"; local r=$? ; (
sleep ${3}m && chmod $m "$2" ) & return $r ; }
$ chmod-t a+w myfile 30
$ chmod-t a+x myfile 30

It's a non-trivial exercise to arrange for "undo" changes to stack rather
than queue, separately for each target.

-Martin

PS: not every "nice to have" idea is actually "nice" in practice; some of
them turn out to be nightmares.

PPS: I suggest looking at overlay filesystems. Or snapshotting filesystems.
Or temporary mounts with UID mapping.
In general this feels like a problem that would be better solved at a
filesystem level, not an extra feature for a low-level command.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.