use try/except pattern

This commit is contained in:
Eray Özkural
2006-06-19 13:47:18 +00:00
parent 9291324866
commit da76604da5
+8 -2
View File
@@ -293,7 +293,8 @@ class Install(AtomicOperation):
assert newf.path == oldf.path assert newf.path == oldf.path
if newf.type == 'config' and oldf.type == 'config': # config upgrade if newf.type == 'config' and oldf.type == 'config': # config upgrade
fpath = pisi.util.join_path(ctx.config.dest_dir(), oldf.path) fpath = pisi.util.join_path(ctx.config.dest_dir(), oldf.path)
if (os.path.isfile(fpath) or os.path.islink(fpath) and not os.path.isdir(fpath)) and os.path.exists(fpath) and pisi.util.sha1_file(fpath) == fileinfo.hash: try:
if pisi.util.sha1_file(fpath) == fileinfo.hash:
# old config file changed, don't overwrite # old config file changed, don't overwrite
config_changed.append(fpath) config_changed.append(fpath)
if os.path.exists(fpath + '.old'): if os.path.exists(fpath + '.old'):
@@ -302,6 +303,8 @@ class Install(AtomicOperation):
else: else:
# old config file not changed, overwrite # old config file not changed, overwrite
pass pass
except pisi.util.FileError, e:
pass
else: else:
for file in self.files.list: for file in self.files.list:
if file.type == 'config': if file.type == 'config':
@@ -479,8 +482,11 @@ class Remove(AtomicOperation):
elif fileinfo.type == ctx.const.conf: elif fileinfo.type == ctx.const.conf:
# config files are precious, leave them as they are # config files are precious, leave them as they are
# unless they are the same as provided by package. # unless they are the same as provided by package.
if (os.path.isfile(fpath) or os.path.islink(fpath)) and os.path.exists(fpath) and pisi.util.sha1_file(fpath) == fileinfo.hash: try:
if pisi.util.sha1_file(fpath) == fileinfo.hash:
os.unlink(fpath) os.unlink(fpath)
except pisi.util.FileError, e:
pass
else: else:
if os.path.isfile(fpath) or os.path.islink(fpath): if os.path.isfile(fpath) or os.path.islink(fpath):
os.unlink(fpath) os.unlink(fpath)