Add support for character and block device files

This commit is contained in:
Jonas Borgström 2012-03-01 22:35:43 +01:00
parent 9d508c9d18
commit 78ab5bd868
2 changed files with 20 additions and 23 deletions

View File

@ -186,19 +186,6 @@ class Archive(object):
os.makedirs(path)
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))
os.mkfifo(path)
self.restore_attrs(path, item)
elif stat.S_ISLNK(mode):
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
source = item['source']
if os.path.exists(path):
os.unlink(path)
os.symlink(source, path)
self.restore_attrs(path, item, symlink=True)
elif stat.S_ISREG(mode):
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
@ -231,7 +218,22 @@ class Archive(object):
else:
for i, (id, size, csize) in enumerate(item['chunks']):
self.store.get(id, callback=extract_cb, callback_data=(id, i))
elif stat.S_ISFIFO(mode):
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
os.mkfifo(path)
self.restore_attrs(path, item)
elif stat.S_ISLNK(mode):
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
source = item['source']
if os.path.exists(path):
os.unlink(path)
os.symlink(source, path)
self.restore_attrs(path, item, symlink=True)
elif stat.S_ISCHR(mode) or stat.S_ISBLK(mode):
os.mknod(path, item['mode'], item['dev'])
self.restore_attrs(path, item)
else:
raise Exception('Unknown archive item type %r' % item['mode'])
@ -328,12 +330,7 @@ class Archive(object):
pass
return item
def process_dir(self, path, st):
item = {'path': path.lstrip('/\\:')}
item.update(self.stat_attrs(st, path))
self.add_item(item)
def process_fifo(self, path, st):
def process_item(self, path, st):
item = {'path': path.lstrip('/\\:')}
item.update(self.stat_attrs(st, path))
self.add_item(item)

View File

@ -130,7 +130,7 @@ class Archiver(object):
return
self.print_verbose(path)
if stat.S_ISDIR(st.st_mode):
archive.process_dir(path, st)
archive.process_item(path, st)
try:
entries = os.listdir(path)
except OSError, e:
@ -139,10 +139,10 @@ class Archiver(object):
for filename in sorted(entries):
self._process(archive, cache, patterns, skip_inodes,
os.path.join(path, filename), restrict_dev)
elif stat.S_ISFIFO(st.st_mode) or stat.S_ISCHR(st.st_mode) or stat.S_ISBLK(st.st_mode):
archive.process_item(path, st)
elif stat.S_ISLNK(st.st_mode):
archive.process_symlink(path, st)
elif stat.S_ISFIFO(st.st_mode):
archive.process_fifo(path, st)
elif stat.S_ISREG(st.st_mode):
try:
archive.process_file(path, st, cache)