From e0615df18792a026a0783a13a8056fa3357eceef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Sun, 7 Aug 2011 12:38:43 +0200 Subject: [PATCH] Defer directory attr restoration to avoid permission problems --- darc/archive.py | 5 +++-- darc/archiver.py | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/darc/archive.py b/darc/archive.py index 213dc5609..c4d1698ac 100644 --- a/darc/archive.py +++ b/darc/archive.py @@ -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)) diff --git a/darc/archiver.py b/darc/archiver.py index 00dd98d37..19dde8dde 100644 --- a/darc/archiver.py +++ b/darc/archiver.py @@ -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)