Preserve file permissions in fakefs after add_real_file #1138
-
Describe the bug If I copy this file into a fake filesystem the user and group are preserved, but the permissions are changed to How To Reproduce import os
from pyfakefs.fake_filesystem import FakeFilesystem
from pyfakefs.fake_os import FakeOsModule
file = '/usr/bin/env'
fs = FakeFilesystem()
fs.add_real_file(file)
real_permissions = oct(os.stat(file).st_mode)
print(f"{real_permissions=}")
fake_os = FakeOsModule(fs)
fake_permissions = oct(fake_os.stat(file).st_mode)
print(f"{fake_permissions=}")
# output
# real_permissions='0o100755'
# fake_permissions='0o100444' Your environment Linux-6.8.0-53-generic-x86_64-with-glibc2.39
Python 3.12.3 (main, Jan 17 2025, 18:03:48) [GCC 13.3.0]
pyfakefs 5.7.4
pytest 8.3.4 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Thanks, I will have a look! |
Beta Was this translation helpful? Give feedback.
-
Ok, I completly forgot that this is expected behavior. By default, files from the real filesystem are mapped as read-only. From the documentation:
Replacing |
Beta Was this translation helpful? Give feedback.
Ok, I completly forgot that this is expected behavior. By default, files from the real filesystem are mapped as read-only. From the documentation:
Replacing
fs.add_real_file(file)
withfs.add_real_file(file, read_only=False)
should give you the wanted behavior.Please check if this is sufficient for you.