Defer directory attr restoration to avoid permission problems

This commit is contained in:
Jonas Borgström 2011-08-07 12:38:43 +02:00
parent ddade8384c
commit e0615df187
2 changed files with 6 additions and 3 deletions

View File

@ -139,7 +139,7 @@ class Archive(object):
cache.rollback()
return stats
def extract_item(self, item, dest=None, start_cb=None):
def extract_item(self, item, dest=None, start_cb=None, restore_attrs=True):
dest = dest or os.getcwdu()
dir_stat_queue = []
assert item['path'][0] not in ('/', '\\', ':')
@ -148,7 +148,8 @@ class Archive(object):
if stat.S_ISDIR(mode):
if not os.path.exists(path):
os.makedirs(path)
self.restore_attrs(path, item)
if restore_attrs:
self.restore_attrs(path, item)
elif stat.S_ISFIFO(mode):
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))

View File

@ -117,9 +117,11 @@ class Archiver(object):
def extract_cb(item):
if exclude_path(item['path'], args.patterns):
return
archive.extract_item(item, args.dest, start_cb)
if stat.S_ISDIR(item['mode']):
dirs.append(item)
archive.extract_item(item, args.dest, start_cb, restore_attrs=False)
else:
archive.extract_item(item, args.dest, start_cb)
if dirs and not item['path'].startswith(dirs[-1]['path']):
# Extract directories twice to make sure mtime is correctly restored
archive.extract_item(dirs.pop(-1), args.dest)