Skip to content
Snippets Groups Projects
Commit 15fb0c4e authored by Simon McVittie's avatar Simon McVittie
Browse files

tests: Assert that pv_cheap_tree_copy copies permissions

parent e244a8ca
No related branches found
No related tags found
No related merge requests found
......@@ -36,25 +36,40 @@ class TestCheapCopy(unittest.TestCase):
equivalent = os.path.join(superset, os.path.relpath(path, subset))
for d in dirs:
if not os.path.isdir(os.path.join(equivalent, d)):
in_subset = os.path.join(path, d)
in_superset = os.path.join(equivalent, d)
if not os.path.isdir(in_superset):
raise AssertionError(
'%r should be a directory', equivalent)
'%r should be a directory', in_superset)
info = os.stat(in_subset)
info2 = os.stat(in_superset)
self.assertEqual(info.st_mode, info2.st_mode)
for f in files:
in_subset = os.path.join(path, f)
in_superset = os.path.join(equivalent, f)
if (
os.path.islink(in_subset)
or not os.path.exists(in_subset)
):
target = os.readlink(in_subset)
target2 = os.readlink(os.path.join(equivalent, f))
target2 = os.readlink(in_superset)
self.assertEqual(target, target2)
else:
info = os.stat(in_subset)
info2 = os.stat(os.path.join(equivalent, f))
info2 = os.stat(in_superset)
# they should be hard links
self.assertEqual(info.st_ino, info2.st_ino)
self.assertEqual(info.st_dev, info2.st_dev)
# These should all be true automatically because
# they're hard links, but to be thorough...
self.assertEqual(info.st_mode, info2.st_mode)
self.assertEqual(info.st_size, info2.st_size)
self.assertEqual(int(info.st_mtime), int(info2.st_mtime))
self.assertEqual(int(info.st_ctime), int(info2.st_ctime))
def assert_tree_is_same(self, left, right):
self.assert_tree_is_superset(left, right)
......@@ -99,6 +114,11 @@ class TestCheapCopy(unittest.TestCase):
with open(os.path.join(source, 'x'), 'w') as writer:
writer.write('hello')
# Use unusual (but safe) permissions to assert that they get
# copied
os.chmod(source, 0o2740)
os.chmod(os.path.join(source, 'x'), 0o651)
with open(os.path.join(source, 'files', 'y'), 'w') as writer:
writer.write('hello')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment