From 18273d470bbda8679a2d76ed90425f6f775ab8d1 Mon Sep 17 00:00:00 2001 From: "Dr. Peter Poeml" Date: Fri, 5 Jun 2009 19:42:33 +0000 Subject: [PATCH] When updating working copies, replace the .osc/_files file in an atomic way, preventing hosed working copies when the update is interrupted. An empty .osc/_files file could result, leading to the following sympton upon subsequent update: % osc up 'foobar' is not a valid working copy. When parsing .osc/_files, the following error was encountered: no element found: line 1, column 0 --- osc/core.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/osc/core.py b/osc/core.py index 29230897..a34792d2 100755 --- a/osc/core.py +++ b/osc/core.py @@ -888,9 +888,16 @@ class Package: It is replaced with the version pulled from upstream. """ meta = ''.join(show_files_meta(self.apiurl, self.prjname, self.name, revision=revision)) - f = open(os.path.join(self.storedir, '_files'), 'w') - f.write(meta) - f.close() + try: + f = open(os.path.join(self.storedir, '_files.new'), 'w') + f.write(meta) + f.close() + os.rename(os.path.join(self.storedir, '_files.new'), os.path.join(self.storedir, '_files')) + except: + raise + finally: + if os.path.exists(os.path.join(self.storedir, '_files.new')): + os.unlink(os.path.join(self.storedir, '_files.new')) def update_datastructs(self): """