Merge branch '5043-crunchstat-long-lines' closes #5043
[arvados.git] / services / fuse / arvados_fuse / __init__.py
index 8c19c312266c1dc3c22c4a73b48407bbd4d719a2..2d4f6c9dcde55eac714f3b2a0171fa3c836b59b6 100644 (file)
@@ -20,6 +20,7 @@ import _strptime
 import calendar
 import threading
 import itertools
+import ciso8601
 
 from arvados.util import portable_data_hash_pattern, uuid_pattern, collection_uuid_pattern, group_uuid_pattern, user_uuid_pattern, link_uuid_pattern
 
@@ -30,46 +31,12 @@ _logger = logging.getLogger('arvados.arvados_fuse')
 # appear as underscores in the fuse mount.)
 _disallowed_filename_characters = re.compile('[\x00/]')
 
-class SafeApi(object):
-    """Threadsafe wrapper for API object.
-
-    This stores and returns a different api object per thread, because
-    httplib2 which underlies apiclient is not threadsafe.
-    """
-
-    def __init__(self, config):
-        self.host = config.get('ARVADOS_API_HOST')
-        self.api_token = config.get('ARVADOS_API_TOKEN')
-        self.insecure = config.flag_is_true('ARVADOS_API_HOST_INSECURE')
-        self.local = threading.local()
-        self.block_cache = arvados.KeepBlockCache()
-
-    def localapi(self):
-        if 'api' not in self.local.__dict__:
-            self.local.api = arvados.api(
-                version='v1',
-                host=self.host, token=self.api_token, insecure=self.insecure)
-        return self.local.api
-
-    def localkeep(self):
-        if 'keep' not in self.local.__dict__:
-            self.local.keep = arvados.KeepClient(api_client=self.localapi(), block_cache=self.block_cache)
-        return self.local.keep
-
-    def __getattr__(self, name):
-        # Proxy nonexistent attributes to the local API client.
-        try:
-            return getattr(self.localapi(), name)
-        except AttributeError:
-            return super(SafeApi, self).__getattr__(name)
-
-
 def convertTime(t):
     """Parse Arvados timestamp to unix time."""
     if not t:
         return 0
     try:
-        return calendar.timegm(time.strptime(t, "%Y-%m-%dT%H:%M:%SZ"))
+        return calendar.timegm(ciso8601.parse_datetime_unaware(t).timetuple())
     except (TypeError, ValueError):
         return 0
 
@@ -306,6 +273,7 @@ class CollectionDirectory(Directory):
             self._mtime = convertTime(collection.get('modified_at'))
         else:
             self.collection_locator = collection
+            self._mtime = 0
 
     def same(self, i):
         return i['uuid'] == self.collection_locator or i['portable_data_hash'] == self.collection_locator
@@ -348,7 +316,7 @@ class CollectionDirectory(Directory):
 
             with llfuse.lock_released:
                 coll_reader = arvados.CollectionReader(
-                    self.collection_locator, self.api, self.api.localkeep(),
+                    self.collection_locator, self.api, self.api.keep,
                     num_retries=self.num_retries)
                 new_collection_object = coll_reader.api_response() or {}
                 # If the Collection only exists in Keep, there will be no API
@@ -933,5 +901,5 @@ class Operations(llfuse.Operations):
     # arv-mount.
     # The workaround is to implement it with the proper number of parameters,
     # and then everything works out.
-    def create(self, p1, p2, p3, p4, p5):
+    def create(self, inode_parent, name, mode, flags, ctx):
         raise llfuse.FUSEError(errno.EROFS)