Fix device node restore issues

This commit is contained in:
Jonas Borgström 2012-03-03 14:02:22 +01:00
parent f7e499ceaa
commit d58784d738
3 changed files with 17 additions and 10 deletions

View File

@ -335,6 +335,11 @@ class Archive(object):
item.update(self.stat_attrs(st, path))
self.add_item(item)
def process_dev(self, path, st):
item = {'path': path.lstrip('/\\:'), 'dev': st.st_dev}
item.update(self.stat_attrs(st, path))
self.add_item(item)
def process_symlink(self, path, st):
source = os.readlink(path)
item = {'path': path.lstrip('/\\:'), 'source': source}

View File

@ -129,7 +129,12 @@ class Archiver(object):
if stat.S_ISSOCK(st.st_mode):
return
self.print_verbose(path)
if stat.S_ISDIR(st.st_mode):
if stat.S_ISREG(st.st_mode):
try:
archive.process_file(path, st, cache)
except IOError, e:
self.print_error('%s: %s', path, e)
elif stat.S_ISDIR(st.st_mode):
archive.process_item(path, st)
try:
entries = os.listdir(path)
@ -139,15 +144,12 @@ 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_ISREG(st.st_mode):
try:
archive.process_file(path, st, cache)
except IOError, e:
self.print_error('%s: %s', path, e)
elif stat.S_ISFIFO(st.st_mode):
archive.process_item(path, st)
elif stat.S_ISCHR(st.st_mode) or stat.S_ISBLK(st.st_mode):
archive.process_dev(path, st)
else:
self.print_error('Unknown file type: %s', path)

View File

@ -293,7 +293,7 @@ def uid2user(uid):
@memoize
def user2uid(user):
try:
return pwd.getpwnam(user).pw_uid
return user and pwd.getpwnam(user).pw_uid
except KeyError:
return None
@ -309,7 +309,7 @@ def gid2group(gid):
@memoize
def group2gid(group):
try:
return grp.getgrnam(group).gr_gid
return group and grp.getgrnam(group).gr_gid
except KeyError:
return None