[Pkg-bazaar-commits] ./bzr/unstable r716: - write into store using AtomicFile
Martin Pool
mbp at sourcefrog.net
Fri Apr 10 08:13:46 UTC 2009
------------------------------------------------------------
revno: 716
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Mon 2005-06-20 14:33:23 +1000
message:
- write into store using AtomicFile
modified:
bzrlib/store.py
-------------- next part --------------
=== modified file 'bzrlib/store.py'
--- a/bzrlib/store.py 2005-06-20 03:54:23 +0000
+++ b/bzrlib/store.py 2005-06-20 04:33:23 +0000
@@ -78,26 +78,35 @@
"""Add contents of a file into the store.
f -- An open file, or file-like object."""
- # FIXME: Only works on smallish files
- # TODO: Can be optimized by copying at the same time as
- # computing the sum.
+ # FIXME: Only works on files that will fit in memory
+
+ from bzrlib.atomicfile import AtomicFile
+
mutter("add store entry %r" % (fileid))
if isinstance(f, types.StringTypes):
content = f
else:
content = f.read()
-
+
p = self._path(fileid)
if os.access(p, os.F_OK) or os.access(p + '.gz', os.F_OK):
raise BzrError("store %r already contains id %r" % (self._basedir, fileid))
+ fn = p
if compressed:
- f = gzip.GzipFile(p + '.gz', 'wb')
- else:
- f = file(p, 'wb')
+ fn = fn + '.gz'
- f.write(content)
- f.close()
+ af = AtomicFile(fn, 'wb')
+ try:
+ if compressed:
+ gf = gzip.GzipFile(mode='wb', fileobj=af)
+ gf.write(content)
+ gf.close()
+ else:
+ af.write(content)
+ af.commit()
+ finally:
+ af.close()
def copy_multi(self, other, ids):
More information about the Pkg-bazaar-commits
mailing list