aboutsummaryrefslogtreecommitdiff
path: root/mini-dinstall
diff options
context:
space:
mode:
authorGuido Guenther <agx@sigxcpu.org>2007-08-23 15:52:10 +0200
committerGuido Guenther <agx@bogon.sigxcpu.org>2007-08-23 15:52:10 +0200
commitb1cc0b013eda181e25052a45b6fdc558ad4b96f0 (patch)
treebbc53ebe372ae624d79f7af21c6a5fa6f077f6b9 /mini-dinstall
parente5f5a2ab23ace19c6de39512f76f8fed5f5ad912 (diff)
update packages files atomically
Diffstat (limited to 'mini-dinstall')
-rwxr-xr-xmini-dinstall20
1 files changed, 13 insertions, 7 deletions
diff --git a/mini-dinstall b/mini-dinstall
index e8386a2..675e422 100755
--- a/mini-dinstall
+++ b/mini-dinstall
@@ -19,7 +19,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os, sys, re, glob, getopt, time, traceback, gzip, getpass, socket
-import signal, threading, select, Queue, SocketServer
+import shutil, signal, threading, select, Queue, SocketServer
import logging, logging.handlers
#logging.basicConfig()
import apt_pkg
@@ -1047,19 +1047,25 @@ class ArchiveDirIndexer(threading.Thread):
os.exit(1)
os.close(outfd)
stdout = os.fdopen(infd)
- packagesfile = open(os.path.join(dir, name), 'w')
- zpackagesfile = gzip.GzipFile(os.path.join(dir, name + '.gz'), 'w')
+ packagesfilename = os.path.join(dir, name)
+ newpackagesfilename = packagesfilename + '.new'
+ zpackagesfilename = packagesfilename + '.gz'
+ newzpackagesfilename = newpackagesfilename + '.gz'
+ newpackagesfile = open(newpackagesfilename, 'w')
+ newzpackagesfile = gzip.GzipFile(newzpackagesfilename, 'w')
buf = stdout.read(8192)
while buf != '':
- packagesfile.write(buf)
- zpackagesfile.write(buf)
+ newpackagesfile.write(buf)
+ newzpackagesfile.write(buf)
buf = stdout.read(8192)
stdout.close()
(pid, status) = os.waitpid(pid, 0)
if not (status is None or (os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0)):
raise DinstallException("apt-ftparchive exited with status code %d" % (status,))
- packagesfile.close()
- zpackagesfile.close()
+ newpackagesfile.close()
+ newzpackagesfile.close()
+ shutil.move(newpackagesfilename, packagesfilename)
+ shutil.move(newzpackagesfilename, zpackagesfilename)
def _make_packagesfile(self, dir):
self._make_indexfile(dir, 'packages', 'Packages')