Fix download in transfer lib.
authorAntony Chazapis <chazapis@gmail.com>
Fri, 2 Dec 2011 12:57:32 +0000 (14:57 +0200)
committerAntony Chazapis <chazapis@gmail.com>
Fri, 2 Dec 2011 12:57:32 +0000 (14:57 +0200)
tools/lib/client.py
tools/lib/transfer.py
tools/test

index 84457d2..a18bbc3 100644 (file)
@@ -410,8 +410,7 @@ class OOS_Client(Client):
         args = locals().copy()
         for elem in ['self', 'container', 'object']:
             args.pop(elem)
-        data = self.retrieve_object(container, object, format='json', **args)
-        return data['hashes']
+        return self.retrieve_object(container, object, format='json', **args)
     
     def create_directory_marker(self, container, object, account=None):
         """creates a dierectory marker"""
index ea0e906..b58b39d 100644 (file)
@@ -82,27 +82,32 @@ def upload(client, path, container, prefix, name=None, mimetype=None):
 
 def download(client, container, object, path):
     
-    meta = client.retrieve_container_metadata(container)
-    blocksize = int(meta['x-container-block-size'])
-    blockhash = meta['x-container-block-hash']
+    res = client.retrieve_object_hashmap(container, object)
+    blocksize = int(res['block_size'])
+    blockhash = res['block_hash']
+    bytes = res['bytes']
+    map = res['hashes']
+    print res
     
     if os.path.exists(path):
-        size = os.path.getsize(path)
-        hashes = HashMap(blocksize, blockhash)
-        hashes.load(open(path))
+        h = HashMap(blocksize, blockhash)
+        h.load(open(path))
+        hashes = [hexlify(x) for x in h]
     else:
         open(path, 'w').close()     # Create an empty file
-        size = 0
         hashes = []
     
-    map = client.retrieve_object_hashmap(container, object)
+    if bytes == 0:
+        return
     
-    with open(path, 'a') as fp:
+    with open(path, 'a+') as fp:
         for i, h in enumerate(map):
             if i < len(hashes) and h == hashes[i]:
                 continue
             start = i * blocksize
-            end = '' if i == len(map) - 1 else (i + 1) * blocksize
+            end = '' if i == len(map) - 1 else ((i + 1) * blocksize) - 1
             data = client.retrieve_object(container, object, range='bytes=%s-%s' % (start, end))
+            if i != len(map) - 1:
+                data += (blocksize - len(data)) * '\x00'
             fp.seek(start)
             fp.write(data)
index eedc098..b27b2f9 100755 (executable)
@@ -1278,7 +1278,7 @@ class ObjectPut(BaseTestCase):
         o = 'object'
         zero = self.client.create_zero_length_object(c, o)
         zero_meta = self.client.retrieve_object_metadata(c, o)
-        zero_hash = self.client.retrieve_object_hashmap(c, o)
+        zero_hash = self.client.retrieve_object_hashmap(c, o)["hashes"]
         zero_data = self.client.retrieve_object(c, o)
         
         self.assertEqual(int(zero_meta['content-length']), 0)
@@ -1558,7 +1558,7 @@ class ObjectPost(BaseTestCase):
         
         source_data = self.client.retrieve_object(c, src)
         source_meta = self.client.retrieve_object_metadata(c, src)
-        source_hash = self.client.retrieve_object_hashmap(c, src)
+        source_hash = self.client.retrieve_object_hashmap(c, src)["hashes"]
         
         #update zero length object
         self.client.create_zero_length_object(c, dest)
@@ -1566,7 +1566,7 @@ class ObjectPost(BaseTestCase):
         self.client.update_from_other_source(c, dest, source_object)
         dest_data = self.client.retrieve_object(c, src)
         dest_meta = self.client.retrieve_object_metadata(c, dest)
-        dest_hash = self.client.retrieve_object_hashmap(c, src)
+        dest_hash = self.client.retrieve_object_hashmap(c, src)["hashes"]
         self.assertEqual(source_data, dest_data)
         self.assertEqual(source_hash, dest_hash)
         
@@ -1630,8 +1630,8 @@ class ObjectPost(BaseTestCase):
         self.assertEqual(self.client.retrieve_object(c, o),
                          self.client.retrieve_object(c, other))
         
-        self.assertEqual(self.client.retrieve_object_hashmap(c, o),
-                         self.client.retrieve_object_hashmap(c, other))
+        self.assertEqual(self.client.retrieve_object_hashmap(c, o)["hashes"],
+                         self.client.retrieve_object_hashmap(c, other)["hashes"])
     
 class ObjectDelete(BaseTestCase):
     def setUp(self):