use try/except pattern

This commit is contained in:
Eray Özkural
2006-06-19 13:47:18 +00:00
parent 9291324866
commit da76604da5
+16 -10
View File
@@ -293,14 +293,17 @@ 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:
# old config file changed, don't overwrite if pisi.util.sha1_file(fpath) == fileinfo.hash:
config_changed.append(fpath) # old config file changed, don't overwrite
if os.path.exists(fpath + '.old'): config_changed.append(fpath)
os.unlink(fpath + '.old') if os.path.exists(fpath + '.old'):
os.rename(fpath, fpath + '.old') os.unlink(fpath + '.old')
else: os.rename(fpath, fpath + '.old')
# old config file not changed, overwrite else:
# old config file not changed, overwrite
pass
except pisi.util.FileError, e:
pass pass
else: else:
for file in self.files.list: for file in self.files.list:
@@ -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:
os.unlink(fpath) if pisi.util.sha1_file(fpath) == fileinfo.hash:
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)