[Pkg-bazaar-commits] ./bzr/unstable r129: Store.add defaults to adding gzipped files
mbp at sourcefrog.net
mbp at sourcefrog.net
Fri Apr 10 07:44:12 UTC 2009
------------------------------------------------------------
revno: 129
committer: mbp at sourcefrog.net
timestamp: Tue 2005-03-29 11:16:16 +1000
message:
Store.add defaults to adding gzipped files
modified:
bzrlib/store.py
-------------- next part --------------
=== modified file 'bzrlib/store.py'
--- a/bzrlib/store.py 2005-03-29 01:08:49 +0000
+++ b/bzrlib/store.py 2005-03-29 01:16:16 +0000
@@ -80,7 +80,7 @@
def __repr__(self):
return "%s(%r)" % (self.__class__.__name__, self._basedir)
- def add(self, f, fileid):
+ def add(self, f, fileid, compressed=True):
"""Add contents of a file into the store.
:param f: An open file, or file-like object."""
@@ -92,14 +92,20 @@
content = f
else:
content = f.read()
- if fileid not in self:
- filename = self._path(fileid)
- f = file(filename, 'wb')
- f.write(content)
- ## f.flush()
- ## os.fsync(f.fileno())
- f.close()
- osutils.make_readonly(filename)
+
+ p = self._path(fileid)
+ if os.access(p, os.F_OK) or os.access(p + '.gz', os.F_OK):
+ bailout("store %r already contains id %r" % (self._basedir, fileid))
+
+ if compressed:
+ f = gzip.GzipFile(p + '.gz', 'wb')
+ os.chmod(p + '.gz', 0444)
+ else:
+ f = file(p, 'wb')
+ os.chmod(p, 0444)
+
+ f.write(content)
+ f.close()
def __contains__(self, fileid):
More information about the Pkg-bazaar-commits
mailing list