From da76604da57b5401488dae5e4ae63900fa9eff2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Mon, 19 Jun 2006 13:47:18 +0000 Subject: [PATCH] use try/except pattern --- pisi/atomicoperations.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pisi/atomicoperations.py b/pisi/atomicoperations.py index 32a7f759..f1ae8d5b 100644 --- a/pisi/atomicoperations.py +++ b/pisi/atomicoperations.py @@ -293,14 +293,17 @@ class Install(AtomicOperation): assert newf.path == oldf.path if newf.type == 'config' and oldf.type == 'config': # config upgrade 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: - # old config file changed, don't overwrite - config_changed.append(fpath) - if os.path.exists(fpath + '.old'): - os.unlink(fpath + '.old') - os.rename(fpath, fpath + '.old') - else: - # old config file not changed, overwrite + try: + if pisi.util.sha1_file(fpath) == fileinfo.hash: + # old config file changed, don't overwrite + config_changed.append(fpath) + if os.path.exists(fpath + '.old'): + os.unlink(fpath + '.old') + os.rename(fpath, fpath + '.old') + else: + # old config file not changed, overwrite + pass + except pisi.util.FileError, e: pass else: for file in self.files.list: @@ -479,8 +482,11 @@ class Remove(AtomicOperation): elif fileinfo.type == ctx.const.conf: # config files are precious, leave them as they are # 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: - os.unlink(fpath) + try: + if pisi.util.sha1_file(fpath) == fileinfo.hash: + os.unlink(fpath) + except pisi.util.FileError, e: + pass else: if os.path.isfile(fpath) or os.path.islink(fpath): os.unlink(fpath)