From 6c11081a21941f25c0c9283f7eaed599fca48294 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Wed, 7 Sep 2011 08:34:38 +0200 Subject: [PATCH] [entropy.spm] PortagePlugin.xpak: properly use open() in ab+ mode --- .../plugins/interfaces/portage_plugin/xpak.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libraries/entropy/spm/plugins/interfaces/portage_plugin/xpak.py b/libraries/entropy/spm/plugins/interfaces/portage_plugin/xpak.py index 3012248a1..4485b1265 100644 --- a/libraries/entropy/spm/plugins/interfaces/portage_plugin/xpak.py +++ b/libraries/entropy/spm/plugins/interfaces/portage_plugin/xpak.py @@ -280,15 +280,13 @@ class tbz2: self.cleanup(datadir) def recompose_mem(self, xpdata): - self.scan() # Don't care about condition... We'll rewrite the data anyway. - myfile = open(self.file, "ab+") - if not myfile: - raise IOError("file not found") - myfile.seek(-self.xpaksize, os.SEEK_END) # 0,2 or -0,2 just mean EOF. - myfile.truncate() - myfile.write(xpdata+encodeint(len(xpdata))+STOP) - myfile.flush() - myfile.close() + self.scan() + with open(self.file, "ab+") as myfile: + myfile.seek(-self.xpaksize, os.SEEK_END) + myfile.truncate() + myfile.write(xpdata+encodeint(len(xpdata))+STOP) + myfile.flush() + myfile.close() return 1 def cleanup(self, datadir):