Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions sshfs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import stat
import weakref
from contextlib import AsyncExitStack, suppress
from datetime import datetime
from datetime import datetime, timezone

import asyncssh
from asyncssh.sftp import SFTPOpUnsupported
Expand Down Expand Up @@ -151,8 +151,16 @@ def _decode_attributes(self, attributes):
"type": kind,
"gid": attributes.gid,
"uid": attributes.uid,
"time": datetime.utcfromtimestamp(attributes.atime),
"mtime": datetime.utcfromtimestamp(attributes.mtime),
"time": (
datetime.fromtimestamp(attributes.atime, tz=timezone.utc)
if attributes.atime is not None
else None
),
"mtime": (
datetime.fromtimestamp(attributes.mtime, tz=timezone.utc)
if attributes.mtime is not None
else None
),
"permissions": attributes.permissions,
}

Expand Down
20 changes: 18 additions & 2 deletions tests/test_sshfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import tempfile
import warnings
from concurrent import futures
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from pathlib import Path

import fsspec
import pytest
from asyncssh.sftp import SFTPFailure
from asyncssh.sftp import SFTPAttrs, SFTPFailure
from importlib_metadata import entry_points

from sshfs import SSHFileSystem
Expand Down Expand Up @@ -116,6 +116,22 @@ def test_info(fs, remote_dir):
assert details["name"] == remote_dir + "/dir/"


def test_info_timestamps_are_tz_aware_utc(fs, remote_dir):
fs.touch(remote_dir + "/a.txt")
details = fs.info(remote_dir + "/a.txt")
for key in ["time", "mtime"]:
assert details[key].tzinfo == timezone.utc

Comment thread
shcheklein marked this conversation as resolved.

def test_decode_attributes_missing_timestamps(fs):
attrs = SFTPAttrs(
permissions=0o100644, size=0, uid=0, gid=0, atime=None, mtime=None
)
details = fs._decode_attributes(attrs)
assert details["time"] is None
assert details["mtime"] is None


def test_move(fs, remote_dir):
fs.touch(remote_dir + "/a.txt")
initial_info = fs.info(remote_dir + "/a.txt")
Expand Down
Loading