Fakeroot Permissions – Issue with Changing Permissions Using Fakeroot

chmodfakerootpermissionsUbuntu

I don't understand why the permission does not change for a user when I run the chmod command with fakeroot.

Initially, the file has these permissions:

-rwxr-xr-x  a.txt*

When I try to change the permission for the file using chmod it works fine:

chmod 111 a.txt

---x--x--x  a.txt*

When I run it with fakeroot it doesn't seem to do the work fine. It sets the permissions for group and other correctly, but not for the user. The permissions for read and write are set, no matter what the 1st value in chmod command is.

fakeroot chmod 111 a.txt

-rwx--x--x  a.txt*

Am I missing something?

Best Answer

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.

Related Question