~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: mbp at sourcefrog
  • Date: 2005-03-29 01:16:16 UTC
  • Revision ID: mbp@sourcefrog.net-20050329011616-04e45f8670fe5141
Store.add defaults to adding gzipped files

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
    def __repr__(self):
81
81
        return "%s(%r)" % (self.__class__.__name__, self._basedir)
82
82
 
83
 
    def add(self, f, fileid):
 
83
    def add(self, f, fileid, compressed=True):
84
84
        """Add contents of a file into the store.
85
85
 
86
86
        :param f: An open file, or file-like object."""
92
92
            content = f
93
93
        else:
94
94
            content = f.read()
95
 
        if fileid not in self:
96
 
            filename = self._path(fileid)
97
 
            f = file(filename, 'wb')
98
 
            f.write(content)
99
 
            ## f.flush()
100
 
            ## os.fsync(f.fileno())
101
 
            f.close()
102
 
            osutils.make_readonly(filename)
 
95
 
 
96
        p = self._path(fileid)
 
97
        if os.access(p, os.F_OK) or os.access(p + '.gz', os.F_OK):
 
98
            bailout("store %r already contains id %r" % (self._basedir, fileid))
 
99
 
 
100
        if compressed:
 
101
            f = gzip.GzipFile(p + '.gz', 'wb')
 
102
            os.chmod(p + '.gz', 0444)
 
103
        else:
 
104
            f = file(p, 'wb')
 
105
            os.chmod(p, 0444)
 
106
            
 
107
        f.write(content)
 
108
        f.close()
103
109
 
104
110
 
105
111
    def __contains__(self, fileid):