piranna / pyfilesystem

Automatically exported from code.google.com/p/pyfilesystem
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

[patch included] TahoeFS support for created/modified time #118

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Following short patch (against current trunk) adds support for correct handling 
of file times (created/modified) in TahoeFS. Please include this patch to 
official source code.

diff --git a/fs/contrib/tahoefs/util.py b/fs/contrib/tahoefs/util.py
--- a/fs/contrib/tahoefs/util.py
+++ b/fs/contrib/tahoefs/util.py
@@ -7,6 +7,7 @@
 import sys

 import platform

 import stat as statinfo

+import datetime

 import fs.errors as errors

 from fs.path import pathsplit

@@ -77,6 +78,13 @@
                 'uri': data.get('rw_uri', data.get('ro_uri'))}

         if 'metadata' in data:

             info['ctime'] = data['metadata'].get('ctime')

+            

+            try:

+                info['modified_time'] = 
datetime.datetime.fromtimestamp(data['metadata']['tahoe']['linkmotime'])

+                info['created_time'] = 
datetime.datetime.fromtimestamp(data['metadata']['tahoe']['linkcrtime'])

+            except KeyError:

+                # Don't break anything if keys aren't found

+                pass

         if info['type'] == 'dirnode':

             info['st_mode'] = 0777 |  statinfo.S_IFDIR 

diff --git a/fs/contrib/tahoefs/__init__.py b/fs/contrib/tahoefs/__init__.py
--- a/fs/contrib/tahoefs/__init__.py
+++ b/fs/contrib/tahoefs/__init__.py
@@ -404,8 +404,4 @@
     def getinfo(self, path): 

         self._log(INFO, 'Reading meta for %s' % path)

         info = self.tahoeutil.info(self.dircap, path)        

-        #import datetime

-        #info['created_time'] = datetime.datetime.now()

-        #info['modified_time'] = datetime.datetime.now()

-        #info['accessed_time'] = datetime.datetime.now()

         return info
\ No newline at end of file

Thanks,
Marek

Original issue reported on code.google.com by ma...@palatinus.cz on 18 May 2012 at 11:54