Skip to content

Commit

Permalink
Fix c,m/time for root folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Xarthisius committed Sep 28, 2017
1 parent 2edd282 commit d55ed65
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions girderfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import diskcache
from fuse import Operations, LoggingMixIn, FuseOSError
import requests
import datetime
import threading
from bson import objectid
from queue import Queue
Expand All @@ -36,6 +37,7 @@ def _lstrip_path(path):
else:
return path_obj


if sys.version_info[0] == 2:
def _convert_time(strtime):
from backports.datetime_timestamp import timestamp
Expand All @@ -44,6 +46,7 @@ def _convert_time(strtime):
def _convert_time(strtime):
return tparse(strtime).timestamp()


class CacheWrapper:
"""
A wrapper cache class that coerces keys to str in order to avoid unicode/str
Expand Down Expand Up @@ -127,7 +130,9 @@ def _get_listing(self, obj_id):
def getattr(self, path, fh=None):
logging.debug("-> getattr({})".format(path))
if path == '/':
return dict(st_mode=(S_IFDIR | 0o755), st_nlink=2)
now = _convert_time(str(datetime.datetime.now()))
return dict(st_mode=(S_IFDIR | 0o755), st_nlink=2,
st_ctime=now, st_atime=now, st_mtime=now)
obj, obj_type = self._get_object_by_path(
self.folder_id, _lstrip_path(path))

Expand Down Expand Up @@ -304,6 +309,7 @@ def release(self, path, fh): # pylint: disable=unused-argument
self.fd -= 1
return self.fd


class DownloadThread(threading.Thread):
def __init__(self, path, stream, fdict, lock, fs):
threading.Thread.__init__(self)
Expand All @@ -318,7 +324,7 @@ def __init__(self, path, stream, fdict, lock, fs):
def run(self):
with tempfile.NamedTemporaryFile(prefix='wtdm', delete=False) as tmp:
self.fdict['path'] = tmp.name
#print self.stream.__dict__
# print self.stream.__dict__
for chunk in self.stream.iter_content(chunk_size=65536):
tmp.write(chunk)
self.fdict['written'] += len(chunk)
Expand Down Expand Up @@ -377,6 +383,7 @@ def assertLocked(self):
if not self.lock.locked():
raise Exception('Lock assertion failed')


class WtDmsGirderFS(GirderFS):
"""
Filesystem for locally mounting a remote Girder folder
Expand Down Expand Up @@ -418,7 +425,7 @@ def _make_dict(self, name, id=None):
if id is None:
id = objectid.ObjectId()
return {'obj': {'_id': id, 'name': name, 'created': self.ctime},
'listing': {'folders': [], 'files':[]},
'listing': {'folders': [], 'files': []},
'dirmap': {}}

def _add_session_entry(self, dict, entry):
Expand Down Expand Up @@ -458,8 +465,8 @@ def read(self, path, size, offset, fh):
return fp.read(size)

def _ensure_region_available(self, path, fdict, fh, offset, size):
obj = fdict['obj']
obj = self._wait_for_file(fdict)
# obj = fdict['obj']
self._wait_for_file(fdict)

if not fdict['downloaded']:
download = False
Expand Down Expand Up @@ -699,7 +706,9 @@ def getattr(self, path, fh=None):
logging.debug("-> getattr({})".format(path))

if path == '/':
return dict(st_mode=(S_IFDIR | 0o755), st_nlink=2)
now = _convert_time(str(datetime.datetime.now()))
return dict(st_mode=(S_IFDIR | 0o755), st_nlink=2,
st_ctime=now, st_atime=now, st_mtime=now)
obj, objType = self._get_object_by_path(
self.folder_id, _lstrip_path(path))

Expand Down Expand Up @@ -844,7 +853,8 @@ def mkdir(self, path, mode):
# The better thing may be to abandon REST and add an API call that allows this to be
# done in one step. Although I suspect this will be a small problem once we
# think about having multiple clients syncing to the same home-dir.
obj = self.girder_cli.post('folder', parameters = {'parentId': parentId, 'name': path.name})
obj = self.girder_cli.post(
'folder', parameters={'parentId': parentId, 'name': path.name})
self._set_metadata(path, {'permissions': mode})
self._cache_add_dir(obj, path)

Expand Down Expand Up @@ -1023,6 +1033,7 @@ def _wait_for_file(self, fdict):
else:
WtDmsGirderFS._wait_for_file(self, fdict)


class LocalGirderFS(GirderFS):
"""
Filesystem for mounting local Girder's FilesystemAssetstore
Expand Down

0 comments on commit d55ed65

Please sign in to comment.