From b07a66d7f9b8981b41e026c4ef46d6f62d431701 Mon Sep 17 00:00:00 2001 From: "beville@gmail.com" Date: Sat, 24 Nov 2012 04:54:36 +0000 Subject: [PATCH] Generatee the temp file for zips in the same folder as original git-svn-id: http://comictagger.googlecode.com/svn/trunk@83 6c5673fe-1810-88d6-992b-cd32ca31540c --- comicarchive.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/comicarchive.py b/comicarchive.py index 86bc415..c34d3d9 100644 --- a/comicarchive.py +++ b/comicarchive.py @@ -85,8 +85,13 @@ class ZipArchiver: # TODO: use tempfile.mkstemp # this recompresses the zip archive, without the files in the exclude_list print "Rebuilding zip {0} without {1}".format( self.path, exclude_list ) + + # generate temp file + tmp_fd, tmp_name = tempfile.mkstemp( dir=os.path.dirname(self.path) ) + os.close( tmp_fd ) + zin = zipfile.ZipFile (self.path, 'r') - zout = zipfile.ZipFile ('tmpnew.zip', 'w') + zout = zipfile.ZipFile (tmp_name, 'w') for item in zin.infolist(): buffer = zin.read(item.filename) if ( item.filename not in exclude_list ): @@ -100,7 +105,7 @@ class ZipArchiver: # replace with the new file os.remove( self.path ) - os.rename( 'tmpnew.zip', self.path ) + os.rename( tmp_name, self.path ) def writeZipComment( self, filename, comment ):