Revision d50ed8d4 snf-pithos-backend/pithos/backends/lib/hashfiler/blocker.py
b/snf-pithos-backend/pithos/backends/lib/hashfiler/blocker.py | ||
---|---|---|
1 | 1 |
# Copyright 2011-2012 GRNET S.A. All rights reserved. |
2 |
#
|
|
2 |
# |
|
3 | 3 |
# Redistribution and use in source and binary forms, with or |
4 | 4 |
# without modification, are permitted provided that the following |
5 | 5 |
# conditions are met: |
6 |
#
|
|
6 |
# |
|
7 | 7 |
# 1. Redistributions of source code must retain the above |
8 | 8 |
# copyright notice, this list of conditions and the following |
9 | 9 |
# disclaimer. |
10 |
#
|
|
10 |
# |
|
11 | 11 |
# 2. Redistributions in binary form must reproduce the above |
12 | 12 |
# copyright notice, this list of conditions and the following |
13 | 13 |
# disclaimer in the documentation and/or other materials |
14 | 14 |
# provided with the distribution. |
15 |
#
|
|
15 |
# |
|
16 | 16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
17 | 17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | 18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
... | ... | |
25 | 25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
26 | 26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
27 | 27 |
# POSSIBILITY OF SUCH DAMAGE. |
28 |
#
|
|
28 |
# |
|
29 | 29 |
# The views and conclusions contained in the software and |
30 | 30 |
# documentation are those of the authors and should not be |
31 | 31 |
# interpreted as representing official policies, either expressed |
... | ... | |
56 | 56 |
if not exists(blockpath): |
57 | 57 |
makedirs(blockpath) |
58 | 58 |
else: |
59 |
raise ValueError("Variable blockpath '%s' is not a directory" % (blockpath,)) |
|
59 |
raise ValueError("Variable blockpath '%s' is not a directory" % |
|
60 |
(blockpath,)) |
|
60 | 61 |
|
61 | 62 |
hashtype = params['hashtype'] |
62 | 63 |
try: |
... | ... | |
125 | 126 |
if not rbl: |
126 | 127 |
break |
127 | 128 |
for block in rbl.sync_read_chunks(blocksize, 1, 0): |
128 |
break # there should be just one block there |
|
129 |
break # there should be just one block there
|
|
129 | 130 |
if not block: |
130 | 131 |
break |
131 | 132 |
append(self._pad(block)) |
... | ... | |
141 | 142 |
block_hash = self.block_hash |
142 | 143 |
hashlist = [block_hash(b) for b in blocklist] |
143 | 144 |
mf = None |
144 |
missing = [i for i, h in enumerate(hashlist) if not self._check_rear_block(h)] |
|
145 |
missing = [i for i, h in enumerate(hashlist) |
|
146 |
if not self._check_rear_block(h)] |
|
145 | 147 |
for i in missing: |
146 | 148 |
with self._get_rear_block(hashlist[i], 1) as rbl: |
147 |
rbl.sync_write(blocklist[i]) #XXX: verify?
|
|
149 |
rbl.sync_write(blocklist[i]) # XXX: verify?
|
|
148 | 150 |
|
149 | 151 |
return hashlist, missing |
150 | 152 |
|
... | ... | |
161 | 163 |
block = self.block_retr((blkhash,)) |
162 | 164 |
if not block: |
163 | 165 |
return None, None |
164 |
|
|
166 |
|
|
165 | 167 |
block = block[0] |
166 | 168 |
newblock = block[:offset] + data |
167 | 169 |
if len(newblock) > blocksize: |
... | ... | |
204 | 206 |
sextend(sl) |
205 | 207 |
lastsize = len(block) |
206 | 208 |
|
207 |
size = (len(hashlist) -1) * blocksize + lastsize if hashlist else 0 |
|
209 |
size = (len(hashlist) - 1) * blocksize + lastsize if hashlist else 0
|
|
208 | 210 |
return size, hashlist, storedlist |
209 |
|
Also available in: Unified diff