~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-23 23:52:10 UTC
  • Revision ID: mbp@sourcefrog.net-20050323235210-5464746b93c39ed0
more notes on darcs

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
__author__ = "Martin Pool <mbp@canonical.com>"
25
25
 
26
26
import os, tempfile, types, osutils
27
 
from stat import ST_SIZE
28
27
from StringIO import StringIO
29
28
from trace import mutter
30
29
 
97
96
            filename = self._path(fileid)
98
97
            f = file(filename, 'wb')
99
98
            f.write(content)
100
 
            ## f.flush()
101
 
            ## os.fsync(f.fileno())
 
99
            f.flush()
 
100
            os.fsync(f.fileno())
102
101
            f.close()
103
102
            osutils.make_readonly(filename)
104
103
 
111
110
    def __iter__(self):
112
111
        return iter(os.listdir(self._basedir))
113
112
 
114
 
    def __len__(self):
115
 
        return len(os.listdir(self._basedir))
116
 
 
117
113
    def __getitem__(self, fileid):
118
114
        """Returns a file reading from a particular entry."""
119
115
        return file(self._path(fileid), 'rb')
120
116
 
121
 
    def total_size(self):
122
 
        """Return (count, bytes)"""
123
 
        total = 0
124
 
        count = 0
125
 
        for fid in self:
126
 
            count += 1
127
 
            total += os.stat(self._path(fid))[ST_SIZE]
128
 
        return count, total
129
 
 
130
117
    def delete_all(self):
131
118
        for fileid in self:
132
119
            self.delete(fileid)