Skip to content

Commit

Permalink
added fault tolerance to rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
lirazsiri committed Aug 10, 2012
1 parent c41a6bf commit c848dbe
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions rollback.py
Expand Up @@ -88,6 +88,7 @@ def rollback_files(self):
changes = Changes.fromfile(self.paths.fsdelta)
dirindex = DirIndex(self.paths.dirindex)

exceptions = 0
for change in changes:
try:
if change.path not in dirindex:
Expand All @@ -111,12 +112,16 @@ def rollback_files(self):
mod = stat.S_IMODE(dirindex_rec.mod)
os.chmod(change.path, mod)
except:
exceptions += 1
# fault-tolerance: warn and continue, don't die
traceback.print_exc(file=sys.stderr)

for fname in ('passwd', 'group'):
shutil.copy(join(self.paths.etc, fname), "/etc")

if exceptions:
raise Error("caught %d exceptions during rollback_files" % exceptions)

def rollback_new_packages(self):
if not exists(self.paths.newpkgs):
return
Expand All @@ -134,11 +139,18 @@ def rollback_database(self):
add_drop_database=True)

def rollback(self):
self.rollback_database()
self.rollback_files()
self.rollback_new_packages()
exceptions = 0
for method in (self.rollback_database, self.rollback_files, self.rollback_new_packages):
try:
method()
except:
exceptions += 1
print >> sys.stderr, "error: %s raised an exception:" % method.__name__
traceback.print_exc(file=sys.stderr)

shutil.rmtree(self.paths)
if exceptions:
raise Error("caught %d exceptions during rollback" % exceptions)

def save_files(self, changes):
for fname in ("passwd", "group"):
Expand Down

0 comments on commit c848dbe

Please sign in to comment.