aboutsummaryrefslogtreecommitdiffstats
path: root/share/ConfigFile.py
diff options
context:
space:
mode:
authorFrederic Lepied <flepied@mandriva.com>2002-01-21 04:04:45 +0000
committerFrederic Lepied <flepied@mandriva.com>2002-01-21 04:04:45 +0000
commitb0d6dc866fc3123b9fb620ee568fed09b211f994 (patch)
tree0b684c50c9f32015ec16c7b3f3d04a7b9f04d9ed /share/ConfigFile.py
parentec734068028cda447b1ed9bc915ddadb6db5972f (diff)
downloadmsec-b0d6dc866fc3123b9fb620ee568fed09b211f994.tar
msec-b0d6dc866fc3123b9fb620ee568fed09b211f994.tar.gz
msec-b0d6dc866fc3123b9fb620ee568fed09b211f994.tar.bz2
msec-b0d6dc866fc3123b9fb620ee568fed09b211f994.tar.xz
msec-b0d6dc866fc3123b9fb620ee568fed09b211f994.zip
protect and log errors on os calls.
Diffstat (limited to 'share/ConfigFile.py')
-rw-r--r--share/ConfigFile.py32
1 files changed, 25 insertions, 7 deletions
diff --git a/share/ConfigFile.py b/share/ConfigFile.py
index 3e24b9b..656c48a 100644
--- a/share/ConfigFile.py
+++ b/share/ConfigFile.py
@@ -59,8 +59,11 @@ def move(old, new):
os.unlink(new)
except OSError:
pass
- os.rename(old, new)
-
+ try:
+ os.rename(old, new)
+ except:
+ error('rename %s %s: %s' % (old, new, sys.exc_value[0]))
+
class ConfigFile:
def __init__(self, path, suffix=None, meta=all_files):
self.meta=meta
@@ -131,7 +134,10 @@ class ConfigFile:
def write(self):
if self.is_deleted:
if self.exists():
- os.unlink(self.path)
+ try:
+ os.unlink(self.path)
+ except:
+ error('unlink %s: %s' % (self.path, sys.exc_value[0]))
log(_('deleted %s') % (self.path,))
elif self.is_modified:
content = string.join(self.lines, "\n")
@@ -141,10 +147,16 @@ class ConfigFile:
self.meta.modified(self.path)
elif self.is_touched:
if os.path.exists(self.path):
- os.utime(self.path, None)
+ try:
+ os.utime(self.path, None)
+ except:
+ error('utime %s: %s' % (self.path, sys.exc_value[0]))
elif self.suffix and os.path.exists(self.path + self.suffix):
move(self.path + self.suffix, self.path)
- os.utime(self.path, None)
+ try:
+ os.utime(self.path, None)
+ except:
+ error('utime %s: %s' % (self.path, sys.exc_value[0]))
else:
self.lines = []
self.is_modified = 1
@@ -160,10 +172,16 @@ class ConfigFile:
# to be fixed: resolv relative symlink
done = (link == self.sym_link)
if not done:
- os.unlink(self.path)
+ try:
+ os.unlink(self.path)
+ except:
+ error('unlink %s: %s' % (self.path, sys.exc_value[0]))
log(_('deleted %s') % (self.path,))
if not done:
- os.symlink(self.sym_link, self.path)
+ try:
+ os.symlink(self.sym_link, self.path)
+ except:
+ error('symlink %s %s: %s' % (self.sym_link, self.path, sys.exc_value[0]))
log(_('made symbolic link from %s to %s') % (self.sym_link, self.path))
if self.is_moved: