Issue with changing permissions with fakeroot
Fakeroot doesn't carry out all the file metadata changes, that's the point: it only pretends to the program that runs under it. Fakeroot does not carry out changes that it can't do, such as changing the owner. It also does not carry out changes that would cause failures down the line. For example, the following code succeeds when run as root, because root can always open files regardless of permissions:
chmod 111 a.txt
cp a.txt b.txt
But when run as a non-root user, cp
fails because it can't read a.txt
. To avoid this, chmod
under fakeroot does not remove permissions from the user.
Fakeroot does pretend to perform the change for the program it's running.
$ stat -c "Before: %A" a.txt; fakeroot sh -c 'chmod 111 a.txt; stat -c "In fakeroot: %A" a.txt'; stat -c "After: %A" a.txt
Before: -rwx--x--x
In fakeroot: ---x--x--x
After: -rwx--x--x
Generally speaking, file metadata changes done inside fakeroot aren't guaranteed to survive the fakeroot call. That's the point. Make a single fakeroot call that does both the metadata changes and whatever operations (such as packing an archive) you want to do with the changed metadata.
This is a quirk of fakeroot
, required to implement its root-masquerading functionality; as documented in a code comment:
if a file is unwritable, then root can still write to it (no matter who owns the file). If we are fakeroot, the only way to fake this is to always make the file writable, readable etc for the real user (who started fakeroot). Also holds for the exec bit of directories.
So fakeroot
always sets u=rwx
, and records the real permissions that were requested in its internal state (which you can save to a file with the -s
option; the resulting file is human-readable). In fact,
chmod 155 a.txt
fakeroot chmod 111 a.txt
will result in a file with 711
permissions!