Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
kamaki
Commits
48c3782c
Commit
48c3782c
authored
Sep 18, 2012
by
Stavros Sachtouris
Browse files
Get rid of pithos_sh hash methods in download
parent
cb73fca1
Changes
2
Hide whitespace changes
Inline
Side-by-side
kamaki/clients/pithos.py
View file @
48c3782c
...
...
@@ -44,7 +44,6 @@ from datetime import datetime
import
sys
from
binascii
import
hexlify
from
.pithos_sh_lib.hashmap
import
HashMap
from
.pithos_rest_api
import
PithosRestAPI
from
.storage
import
ClientError
...
...
@@ -252,6 +251,13 @@ class PithosClient(PithosRestAPI):
self
.
async_pool
.
start
(
g
)
return
g
def
_hash_from_file
(
self
,
fp
,
start
,
size
,
blockhash
):
fp
.
seek
(
start
)
block
=
fp
.
read
(
size
)
h
=
newhashlib
(
blockhash
)
h
.
update
(
block
.
strip
(
'
\x00
'
))
return
hexlify
(
h
.
digest
())
def
_greenlet2file
(
self
,
flying_greenlets
,
local_file
,
**
restargs
):
finished
=
[]
for
start
,
g
in
flying_greenlets
.
items
():
...
...
@@ -270,16 +276,12 @@ class PithosClient(PithosRestAPI):
blockhash
=
None
,
resume
=
False
,
**
restargs
):
file_size
=
fstat
(
local_file
.
fileno
()).
st_size
if
resume
else
0
if
resume
:
file_hashtool
=
HashMap
(
blocksize
,
blockhash
)
flying_greenlets
=
{}
finished_greenlets
=
[]
for
block_hash
,
blockid
in
remote_hashes
.
items
():
start
=
blocksize
*
blockid
if
start
<
file_size
:
existing_hash
=
hexlify
(
file_hashtool
.
get_hash
(
local_file
,
start
,
blocksize
))
if
existing_hash
==
block_hash
:
if
start
<
file_size
and
block_hash
==
self
.
_hash_from_file
(
local_file
,
start
,
blocksize
,
blockhash
):
self
.
_cb_next
()
continue
if
len
(
flying_greenlets
)
>=
self
.
POOL_SIZE
:
...
...
kamaki/clients/pithos_sh_lib/hashmap.py
View file @
48c3782c
...
...
@@ -93,7 +93,11 @@ class HashMap(list):
def
get_hash
(
self
,
fp
,
start
,
size
):
fp
.
seek
(
start
)
block
=
fp
.
read
(
size
)
return
self
.
_hash_block
(
block
)
h
=
hashlib
.
new
(
self
.
blockhash
)
h
.
update
(
block
.
strip
(
'
\x00
'
))
return
h
.
digest
()
#r = self._hash_raw(block.strip('\x00'))
#return r
def
merkle
(
path
,
blocksize
=
4194304
,
blockhash
=
'sha256'
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment