Revision c4399e62 snf-pithos-backend/pithos/backends/lib/hashfiler/filemapper.py
b/snf-pithos-backend/pithos/backends/lib/hashfiler/filemapper.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from os import makedirs, unlink
|
|
34 |
from os import makedirs |
|
35 | 35 |
from os.path import isdir, realpath, exists, join |
36 | 36 |
from binascii import hexlify |
37 | 37 |
|
... | ... | |
57 | 57 |
raise ValueError("Variable mappath '%s' is not a directory" % (mappath,)) |
58 | 58 |
self.mappath = mappath |
59 | 59 |
|
60 |
def _get_rear_map(self, maphash, create=0):
|
|
60 |
def _get_rear_map(self, maphash, create=True, write=False):
|
|
61 | 61 |
filename = hexlify(maphash) |
62 | 62 |
path = join(self.mappath, |
63 | 63 |
filename[0:2], filename[2:4], filename[4:6], |
64 | 64 |
filename) |
65 |
return ContextFile(path, create) |
|
65 |
return ContextFile(path, create=create, write=write)
|
|
66 | 66 |
|
67 | 67 |
def _check_rear_map(self, maphash): |
68 | 68 |
filename = hexlify(maphash) |
... | ... | |
79 | 79 |
namelen = self.namelen |
80 | 80 |
hashes = () |
81 | 81 |
|
82 |
with self._get_rear_map(maphash, 0) as rmap:
|
|
82 |
with self._get_rear_map(maphash, create=False, write=False) as rmap:
|
|
83 | 83 |
if rmap: |
84 | 84 |
hashes = list(rmap.sync_read_chunks(namelen, nr, blkoff)) |
85 | 85 |
return hashes |
86 | 86 |
|
87 |
def map_stor(self, maphash, hashes=(), blkoff=0, create=1):
|
|
87 |
def map_stor(self, maphash, hashes=(), blkoff=0, create=True):
|
|
88 | 88 |
"""Store hashes in the given hashes map.""" |
89 | 89 |
namelen = self.namelen |
90 | 90 |
if self._check_rear_map(maphash): |
91 | 91 |
return |
92 |
with self._get_rear_map(maphash, 1) as rmap:
|
|
92 |
with self._get_rear_map(maphash, create=create, write=True) as rmap:
|
|
93 | 93 |
rmap.sync_write_chunks(namelen, blkoff, hashes, None) |
94 |
|
|
94 |
# |
Also available in: Unified diff