]> arthur.barton.de Git - bup.git/commitdiff
Use mkstemp() when creating temporary packfiles.
authorAvery Pennarun <apenwarr@gmail.com>
Sat, 30 Jan 2010 21:31:27 +0000 (16:31 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 31 Jan 2010 01:31:01 +0000 (20:31 -0500)
Using getpid() was an okay hack, but there's no good excuse for doing it
that way when there are perfectly good tempfile-naming functions around
already.

git.py

diff --git a/git.py b/git.py
index 17edcca457902c0a8856370c8995b0069ac0e9c2..0f05248ce54d7c915ced76a2e65022c3187699ca 100644 (file)
--- a/git.py
+++ b/git.py
@@ -1,4 +1,4 @@
-import os, errno, zlib, time, sha, subprocess, struct, stat, re
+import os, errno, zlib, time, sha, subprocess, struct, stat, re, tempfile
 from helpers import *
 
 verbose = 0
@@ -289,8 +289,10 @@ class PackWriter:
     def _open(self):
         if not self.file:
             self._make_objcache()
-            self.filename = repo('objects/bup%d' % os.getpid())
-            self.file = open(self.filename + '.pack', 'w+')
+            (fd,name) = tempfile.mkstemp(suffix='.pack', dir=repo('objects'))
+            self.file = os.fdopen(fd, 'w+b')
+            assert(name.endswith('.pack'))
+            self.filename = name[:-5]
             self.file.write('PACK\0\0\0\2\0\0\0\0')
 
     def _raw_write(self, datalist):