mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-27 02:08:54 +00:00
Fix read-only tests for fakeroot environment
This commit is contained in:
parent
dc95c88242
commit
07e445f026
1 changed files with 9 additions and 4 deletions
|
@ -284,8 +284,13 @@ def wait_for_mountstate(self, mountpoint, *, mounted, timeout=5):
|
||||||
def read_only(self, path):
|
def read_only(self, path):
|
||||||
"""Some paths need to be made read-only for testing
|
"""Some paths need to be made read-only for testing
|
||||||
|
|
||||||
Using chmod to remove write permissions is not enough due to
|
If the tests are executed inside a fakeroot environment, the
|
||||||
the tests running with root privileges. Instead, the folder is
|
changes from chmod won't affect the real permissions of that
|
||||||
|
folder. This issue is circumvented by temporarily disabling
|
||||||
|
fakeroot with `LD_PRELOAD=`.
|
||||||
|
|
||||||
|
Using chmod to remove write permissions is not enough if the
|
||||||
|
tests are running with root privileges. Instead, the folder is
|
||||||
rendered immutable with chattr or chflags, respectively.
|
rendered immutable with chattr or chflags, respectively.
|
||||||
"""
|
"""
|
||||||
if sys.platform.startswith('linux'):
|
if sys.platform.startswith('linux'):
|
||||||
|
@ -301,13 +306,13 @@ def read_only(self, path):
|
||||||
message = 'Testing read-only repos is not supported on platform %s' % sys.platform
|
message = 'Testing read-only repos is not supported on platform %s' % sys.platform
|
||||||
self.skipTest(message)
|
self.skipTest(message)
|
||||||
try:
|
try:
|
||||||
os.system('chmod -R ugo-w "%s"' % path)
|
os.system('LD_PRELOAD= chmod -R ugo-w "%s"' % path)
|
||||||
os.system(cmd_immutable)
|
os.system(cmd_immutable)
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
# Restore permissions to ensure clean-up doesn't fail
|
# Restore permissions to ensure clean-up doesn't fail
|
||||||
os.system(cmd_mutable)
|
os.system(cmd_mutable)
|
||||||
os.system('chmod -R ugo+w "%s"' % path)
|
os.system('LD_PRELOAD= chmod -R ugo+w "%s"' % path)
|
||||||
|
|
||||||
|
|
||||||
class changedir:
|
class changedir:
|
||||||
|
|
Loading…
Reference in a new issue