From 3900808197f0cdb051f2b83f240f9eb1413dd768 Mon Sep 17 00:00:00 2001 From: Andrey Tsibin Date: Mon, 11 Jan 2021 15:42:41 +0300 Subject: [PATCH] Respect local time zone in pipe fuse (#1712) --- pipe-cli/mount/pipefuse/cache.py | 4 ++-- pipe-cli/mount/pipefuse/gcp.py | 6 +++--- pipe-cli/mount/pipefuse/pipefs.py | 3 ++- pipe-cli/mount/pipefuse/s3.py | 6 +++--- pipe-cli/mount/pipefuse/webdav.py | 4 +++- pipe-cli/mount/requirements.txt | 1 + 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pipe-cli/mount/pipefuse/cache.py b/pipe-cli/mount/pipefuse/cache.py index 6d755e3fa8..c4f3feffcd 100644 --- a/pipe-cli/mount/pipefuse/cache.py +++ b/pipe-cli/mount/pipefuse/cache.py @@ -18,7 +18,7 @@ from datetime import datetime from threading import RLock -import pytz +from dateutil.tz import tzlocal from fsclient import File, FileSystemClientDecorator import fuseutils @@ -204,7 +204,7 @@ def _uncached_ls_as_dict(self, path, depth=1): def _root(self): return File(name='root', size=0, - mtime=time.mktime(datetime.now(tz=pytz.utc).timetuple()), + mtime=time.mktime(datetime.now(tz=tzlocal()).timetuple()), ctime=None, contenttype=None, is_dir=True) diff --git a/pipe-cli/mount/pipefuse/gcp.py b/pipe-cli/mount/pipefuse/gcp.py index 46d674b952..1607b12bd3 100644 --- a/pipe-cli/mount/pipefuse/gcp.py +++ b/pipe-cli/mount/pipefuse/gcp.py @@ -4,7 +4,7 @@ import time from datetime import datetime -import pytz +from dateutil.tz import tzlocal from google.auth import _helpers from google.auth.transport.requests import AuthorizedSession from google.cloud.storage import Bucket, Blob, Client @@ -252,7 +252,7 @@ def ls(self, path, depth=1): def _get_file_object(self, blob, prefix, recursive): return File(name=self._get_object_name(blob.name, prefix, recursive), size=blob.size, - mtime=time.mktime(blob.updated.astimezone(pytz.utc).timetuple()), + mtime=time.mktime(blob.updated.astimezone(tzlocal()).timetuple()), ctime=None, contenttype='', is_dir=False) @@ -260,7 +260,7 @@ def _get_file_object(self, blob, prefix, recursive): def _get_folder_object(self, name, prefix, recursive): return File(name=self._get_object_name(name, prefix, recursive), size=0, - mtime=time.mktime(datetime.now(tz=pytz.utc).timetuple()), + mtime=time.mktime(datetime.now(tz=tzlocal()).timetuple()), ctime=None, contenttype='', is_dir=True) diff --git a/pipe-cli/mount/pipefuse/pipefs.py b/pipe-cli/mount/pipefuse/pipefs.py index 3ff152ad0d..0947efbea7 100644 --- a/pipe-cli/mount/pipefuse/pipefs.py +++ b/pipe-cli/mount/pipefuse/pipefs.py @@ -22,6 +22,7 @@ import time import easywebdav +from dateutil.tz import tzlocal from fuse import FuseOSError, Operations from threading import RLock @@ -139,7 +140,7 @@ def getattr(self, path, fh=None): 'st_mode': mode | self.mode, 'st_gid': os.getgid(), 'st_uid': os.getuid(), - 'st_atime': time.mktime(datetime.datetime.now().timetuple()) + 'st_atime': time.mktime(datetime.datetime.now(tz=tzlocal()).timetuple()) } if props.mtime: attrs['st_mtime'] = props.mtime diff --git a/pipe-cli/mount/pipefuse/s3.py b/pipe-cli/mount/pipefuse/s3.py index 2da9ba250c..432dfe94e8 100644 --- a/pipe-cli/mount/pipefuse/s3.py +++ b/pipe-cli/mount/pipefuse/s3.py @@ -18,11 +18,11 @@ import time from datetime import datetime -import pytz from boto3 import Session from botocore.config import Config from botocore.credentials import RefreshableCredentials from botocore.session import get_session +from dateutil.tz import tzlocal import fuseutils from fsclient import File @@ -210,7 +210,7 @@ def _matching_paths(self, items, path): def get_folder_object(self, name): return File(name=name, size=0, - mtime=time.mktime(datetime.now(tz=pytz.utc).timetuple()), + mtime=time.mktime(datetime.now(tz=tzlocal()).timetuple()), ctime=None, contenttype='', is_dir=True) @@ -221,7 +221,7 @@ def get_file_name(self, file, prefix, recursive): def get_file_object(self, file, name): return File(name=name, size=file.get('Size', ''), - mtime=time.mktime(file['LastModified'].astimezone(pytz.utc).timetuple()), + mtime=time.mktime(file['LastModified'].astimezone(tzlocal()).timetuple()), ctime=None, contenttype='', is_dir=False) diff --git a/pipe-cli/mount/pipefuse/webdav.py b/pipe-cli/mount/pipefuse/webdav.py index 20c775d5a1..7683ab08c7 100644 --- a/pipe-cli/mount/pipefuse/webdav.py +++ b/pipe-cli/mount/pipefuse/webdav.py @@ -21,8 +21,10 @@ from numbers import Number import easywebdav +import pytz import requests import urllib3 +from dateutil.tz import tzlocal from requests import cookies import fuseutils @@ -109,7 +111,7 @@ def parse_timestamp(self, value, date_format): return try: time_value = datetime.datetime.strptime(value, date_format) - return time.mktime(time_value.timetuple()) + return time.mktime(time_value.replace(tzinfo=pytz.UTC).astimezone(tzlocal()).timetuple()) except ValueError as e: logging.error( 'Failed to parse date: %s. Expected format: "%s". Error: "%s"' % (value, date_format, str(e))) diff --git a/pipe-cli/mount/requirements.txt b/pipe-cli/mount/requirements.txt index 2a92ec1a4d..be49dbd3c8 100644 --- a/pipe-cli/mount/requirements.txt +++ b/pipe-cli/mount/requirements.txt @@ -10,3 +10,4 @@ cachetools==3.1.1 python-intervals==1.10.0 google-resumable-media==0.3.2 google-cloud-storage==1.15.0 +python-dateutil=2.8.1