Revision 6f08f063 snf-pithos-backend/pithos/backends/lib/hashfiler/fileblocker.py

b/snf-pithos-backend/pithos/backends/lib/hashfiler/fileblocker.py
37 37
from binascii import hexlify
38 38

  
39 39
from context_file import ContextFile, file_sync_read_chunks
40
from os import O_RDONLY, O_WRONLY
40 41

  
41 42

  
42 43
class FileBlocker(object):
......
78 79
    def _pad(self, block):
79 80
        return block + ('\x00' * (self.blocksize - len(block)))
80 81

  
81
    def _get_rear_block(self, blkhash, create=0):
82
    def _read_rear_block(self, blkhash):
83
        filename = hexlify(blkhash)
84
        dir = join(self.blockpath, filename[0:2], filename[2:4], filename[4:6])
85
        name = join(dir, filename)
86
        return ContextFile(name, O_RDONLY)
87

  
88
    def _write_rear_block(self, blkhash):
82 89
        filename = hexlify(blkhash)
83 90
        dir = join(self.blockpath, filename[0:2], filename[2:4], filename[4:6])
84 91
        if not exists(dir):
85 92
            makedirs(dir)
86 93
        name = join(dir, filename)
87
        return ContextFile(name, create)
94
        return ContextFile(name, O_WRONLY)
88 95

  
89 96
    def _check_rear_block(self, blkhash):
90 97
        filename = hexlify(blkhash)
......
122 129
            if h == self.emptyhash:
123 130
                append(self._pad(''))
124 131
                continue
125
            with self._get_rear_block(h, 0) as rbl:
132
            with self._read_rear_block(h) as rbl:
126 133
                if not rbl:
127 134
                    break
128 135
                for block in rbl.sync_read_chunks(blocksize, 1, 0):
......
144 151
        missing = [i for i, h in enumerate(hashlist) if not
145 152
                   self._check_rear_block(h)]
146 153
        for i in missing:
147
            with self._get_rear_block(hashlist[i], 1) as rbl:
154
            with self._write_rear_block(hashlist[i]) as rbl:
148 155
                rbl.sync_write(blocklist[i])  # XXX: verify?
149 156

  
150 157
        return hashlist, missing

Also available in: Unified diff