~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:08:49 UTC
  • Revision ID: mbp@sourcefrog.net-20050329010849-0881ad63a124f83e
More support for compressed files in stores

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
 
105
105
    def __contains__(self, fileid):
106
106
        """"""
107
 
        return os.access(self._path(fileid), os.R_OK)
 
107
        p = self._path(fileid)
 
108
        return (os.access(p, os.R_OK)
 
109
                or os.access(p + '.gz', os.R_OK))
108
110
 
 
111
    # TODO: Guard against the same thing being stored twice, compressed and uncompresse
109
112
 
110
113
    def __iter__(self):
111
 
        return iter(os.listdir(self._basedir))
 
114
        for f in os.listdir(self._basedir):
 
115
            if f[-3:] == '.gz':
 
116
                # TODO: case-insensitive?
 
117
                yield f[:-3]
 
118
            else:
 
119
                yield f
112
120
 
113
121
    def __len__(self):
114
122
        return len(os.listdir(self._basedir))
133
141
        count = 0
134
142
        for fid in self:
135
143
            count += 1
136
 
            total += os.stat(self._path(fid))[ST_SIZE]
 
144
            p = self._path(fid)
 
145
            try:
 
146
                total += os.stat(p)[ST_SIZE]
 
147
            except OSError:
 
148
                total += os.stat(p + '.gz')[ST_SIZE]
 
149
                
137
150
        return count, total
138
151
 
139
152
    def delete_all(self):
146
159
        Most stores will be add-only."""
147
160
        filename = self._path(fileid)
148
161
        ## osutils.make_writable(filename)
 
162
        ## TODO: handle gzip
149
163
        os.remove(filename)
150
164
 
151
165
    def destroy(self):