Revision c30635bf snf-pithos-backend/pithos/backends/lib/hashfiler/store.py
b/snf-pithos-backend/pithos/backends/lib/hashfiler/store.py | ||
---|---|---|
40 | 40 |
"""Store. |
41 | 41 |
Required constructor parameters: path, block_size, hash_algorithm, umask. |
42 | 42 |
""" |
43 |
|
|
43 |
|
|
44 | 44 |
def __init__(self, **params): |
45 | 45 |
umask = params['umask'] |
46 | 46 |
if umask is not None: |
47 | 47 |
os.umask(umask) |
48 |
|
|
48 |
|
|
49 | 49 |
path = params['path'] |
50 | 50 |
if path and not os.path.exists(path): |
51 | 51 |
os.makedirs(path) |
52 | 52 |
if not os.path.isdir(path): |
53 | 53 |
raise RuntimeError("Cannot open path '%s'" % (path,)) |
54 |
|
|
54 |
|
|
55 | 55 |
p = {'blocksize': params['block_size'], |
56 | 56 |
'blockpath': os.path.join(path + '/blocks'), |
57 | 57 |
'hashtype': params['hash_algorithm']} |
... | ... | |
59 | 59 |
p = {'mappath': os.path.join(path + '/maps'), |
60 | 60 |
'namelen': self.blocker.hashlen} |
61 | 61 |
self.mapper = Mapper(**p) |
62 |
|
|
62 |
|
|
63 | 63 |
def map_get(self, name): |
64 | 64 |
return self.mapper.map_retr(name) |
65 |
|
|
65 |
|
|
66 | 66 |
def map_put(self, name, map): |
67 | 67 |
self.mapper.map_stor(name, map) |
68 |
|
|
68 |
|
|
69 | 69 |
def map_delete(self, name): |
70 | 70 |
pass |
71 |
|
|
71 |
|
|
72 | 72 |
def block_get(self, hash): |
73 | 73 |
blocks = self.blocker.block_retr((hash,)) |
74 | 74 |
if not blocks: |
75 | 75 |
return None |
76 | 76 |
return blocks[0] |
77 |
|
|
77 |
|
|
78 | 78 |
def block_put(self, data): |
79 | 79 |
hashes, absent = self.blocker.block_stor((data,)) |
80 | 80 |
return hashes[0] |
81 |
|
|
81 |
|
|
82 | 82 |
def block_update(self, hash, offset, data): |
83 | 83 |
h, e = self.blocker.block_delta(hash, offset, data) |
84 | 84 |
return h |
85 |
|
|
85 |
|
|
86 | 86 |
def block_search(self, map): |
87 | 87 |
return self.blocker.block_ping(map) |
88 | 88 |
|
Also available in: Unified diff