From 8e9de79b429911492b3e400afc626538b31f86c7 Mon Sep 17 00:00:00 2001 From: bescoto Date: Sun, 28 Sep 2003 17:52:55 +0000 Subject: Final fix for unreadable file regress error? git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/branches/r0-12@460 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109 --- rdiff-backup/rdiff_backup/regress.py | 22 +++++++++------------- rdiff-backup/testing/regresstest.py | 4 ++-- rdiff-backup/testing/roottest.py | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/rdiff-backup/rdiff_backup/regress.py b/rdiff-backup/rdiff_backup/regress.py index b619fea..bcd1cd0 100644 --- a/rdiff-backup/rdiff_backup/regress.py +++ b/rdiff-backup/rdiff_backup/regress.py @@ -114,27 +114,23 @@ def remove_rbdir_increments(): def iterate_raw_rfs(mirror_rp, inc_rp): """Iterate all RegressFile objects in mirror/inc directory - Also changes permissions of unreadable files to allow access and - then changes them back later. + Also changes permissions of unreadable files. We don't have to + change them back later because regress will do that for us. """ root_rf = RegressFile(mirror_rp, inc_rp, restore.get_inclist(inc_rp)) def helper(rf): mirror_rp = rf.mirror_rp - if (Globals.process_uid != 0 and - ((mirror_rp.isreg() and not mirror_rp.readable()) or - (mirror_rp.isdir() and not mirror_rp.hasfullperms()))): - unreadable, old_perms = 1, mirror_rp.getperms() - if mirror_rp.isreg(): mirror_rp.chmod(0400 | old_perms) - else: mirror_rp.chmod(0700 | old_perms) - else: unreadable = 0 + if Globals.process_uid != 0: + if mirror_rp.isreg() and not mirror_rp.readable(): + mirror_rp.chmod(0400 | mirror_rp.getperms()) + elif mirror_rp.isdir() and not mirror_rp.hasfullperms(): + mirror_rp.chmod(0700 | mirror_rp.getperms()) yield rf - if unreadable and mirror_rp.isreg(): mirror_rp.chmod(old_perms) if rf.mirror_rp.isdir() or rf.inc_rp.isdir(): for sub_rf in rf.yield_sub_rfs(): for sub_sub_rf in helper(sub_rf): yield sub_sub_rf - if unreadable and mirror_rp.isdir(): mirror_rp.chmod(old_perms) return helper(root_rf) def yield_metadata(): @@ -249,14 +245,14 @@ class RegressITRB(rorpiter.ITRBranch): if rf.mirror_rp.isreg(): tf = TempFile.new(rf.mirror_rp) tf.write_from_fileobj(rf.get_restore_fp()) - rpath.copy_attribs(rf.metadata_rorp, tf) tf.fsync_with_dir() # make sure tf fully written before move + rpath.copy_attribs(rf.metadata_rorp, tf) rpath.rename(tf, rf.mirror_rp) # move is atomic else: if rf.mirror_rp.lstat(): rf.mirror_rp.delete() rf.mirror_rp.write_from_fileobj(rf.get_restore_fp()) rpath.copy_attribs(rf.metadata_rorp, rf.mirror_rp) - rf.mirror_rp.fsync_with_dir() # require move before inc delete + rf.mirror_rp.get_parent_rp().fsync() # require move before inc delete def start_process(self, index, rf): """Start processing directory""" diff --git a/rdiff-backup/testing/regresstest.py b/rdiff-backup/testing/regresstest.py index a94f4ae..4920a7e 100644 --- a/rdiff-backup/testing/regresstest.py +++ b/rdiff-backup/testing/regresstest.py @@ -132,8 +132,8 @@ class RegressTest(unittest.TestCase): """Change attributes in directory, so regress will request fp""" subdir = self.output_rp.append('unreadable_dir') assert subdir.lstat() - filerp = subdir.append('to_be_unreadable') - filerp.chmod(0) + rp1_1 = subdir.append('to_be_unreadable') + rp1_1.chmod(0) subdir.chmod(0) diff --git a/rdiff-backup/testing/roottest.py b/rdiff-backup/testing/roottest.py index 3aa6d42..e89a48e 100644 --- a/rdiff-backup/testing/roottest.py +++ b/rdiff-backup/testing/roottest.py @@ -81,6 +81,23 @@ class HalfRoot(unittest.TestCase): rp2_3.chmod(0) return rp1, rp2 + def cause_regress(self, rp): + """Change some of the above to trigger regress""" + rp1_1 = rp.append('foo') + rp1_1.chmod(04) + rp_new = rp.append('lala') + rp_new.write_string('asoentuh') + rp_new.chmod(0) + assert not os.system('chown %s %s' % (user, rp_new.path)) + rp1_3 = rp.append('unreadable_dir') + rp1_3.chmod(0700) + rp1_3_1 = rp1_3.append('file_inside') + rp1_3_1.chmod(01) + rp1_3.chmod(0) + + rbdir = rp.append('rdiff-backup-data') + rbdir.append('current_mirror.2000-12-31T21:33:20-07:00.data').touch() + def test_backup(self): """Test back up, simple restores""" in_rp1, in_rp2 = self.make_dirs() @@ -128,6 +145,12 @@ class HalfRoot(unittest.TestCase): assert rout_perms == 0, rout_perms assert outrp_perms == 0, outrp_perms + self.cause_regress(outrp) + cmd5 = ('su -c "rdiff-backup --check-destination-dir %s" %s' % + (outrp.path, user)) + print "Executing regress: ", cmd5 + assert not os.system(cmd5) + class NonRoot(unittest.TestCase): """Test backing up as non-root user -- cgit v1.2.1