You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2012/12/30 00:40:48 UTC

svn commit: r1426858 - in /libcloud/trunk/libcloud: storage/drivers/local.py test/storage/test_local.py

Author: tomaz
Date: Sat Dec 29 23:40:48 2012
New Revision: 1426858

URL: http://svn.apache.org/viewvc?rev=1426858&view=rev
Log:
Include object hash in the local storage driver.

Contributed by Mahendra M part of LIBCLOUD-273.

Modified:
    libcloud/trunk/libcloud/storage/drivers/local.py
    libcloud/trunk/libcloud/test/storage/test_local.py

Modified: libcloud/trunk/libcloud/storage/drivers/local.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/storage/drivers/local.py?rev=1426858&r1=1426857&r2=1426858&view=diff
==============================================================================
--- libcloud/trunk/libcloud/storage/drivers/local.py (original)
+++ libcloud/trunk/libcloud/storage/drivers/local.py Sat Dec 29 23:40:48 2012
@@ -76,6 +76,7 @@ class LocalStorageDriver(StorageDriver):
     connectionCls = Connection
     name = 'Local Storage'
     website = 'http://example.com'
+    hash_type = 'md5'
 
     def __init__(self, key, secret=None, secure=True, host=None, port=None,
                  **kwargs):
@@ -169,13 +170,20 @@ class LocalStorageDriver(StorageDriver):
             raise ObjectDoesNotExistError(value=None, driver=self,
                                           object_name=object_name)
 
+        # Make a hash for the file based on the metadata. We can safely
+        # use only the mtime attribute here. If the file contents change,
+        # the underlying file-system will change mtime
+        data_hash = self._get_hash_function()
+        data_hash.update(str(stat.st_mtime))
+        data_hash = data_hash.hexdigest()
+
         extra = {}
         extra['creation_time'] = stat.st_ctime
         extra['access_time'] = stat.st_atime
         extra['modify_time'] = stat.st_mtime
 
         return Object(name=object_name, size=stat.st_size, extra=extra,
-                      driver=self, container=container, hash=None,
+                      driver=self, container=container, hash=data_hash,
                       meta_data=None)
 
     def iterate_containers(self):

Modified: libcloud/trunk/libcloud/test/storage/test_local.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/test/storage/test_local.py?rev=1426858&r1=1426857&r2=1426858&view=diff
==============================================================================
--- libcloud/trunk/libcloud/test/storage/test_local.py (original)
+++ libcloud/trunk/libcloud/test/storage/test_local.py Sat Dec 29 23:40:48 2012
@@ -99,7 +99,7 @@ class LocalTests(unittest.TestCase):
         self.assertEqual(len(objects), 5)
 
         for obj in objects:
-            self.assertEqual(obj.hash, None)
+            self.assertNotEqual(obj.hash, None)
             self.assertEqual(obj.size, 4096)
             self.assertEqual(obj.container.name, 'test3')
             self.assertTrue('creation_time' in obj.extra)
@@ -157,7 +157,7 @@ class LocalTests(unittest.TestCase):
         self.assertEqual(obj.name, 'test')
         self.assertEqual(obj.container.name, 'test5')
         self.assertEqual(obj.size, 4096)
-        self.assertEqual(obj.hash, None)
+        self.assertNotEqual(obj.hash, None)
         self.assertTrue('creation_time' in obj.extra)
         self.assertTrue('modify_time' in obj.extra)
         self.assertTrue('access_time' in obj.extra)