Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
38 changes: 19 additions & 19 deletions fs/ftpfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from .path import basename
from .path import normpath
from .path import split
from .time import epoch_to_datetime
from . import _ftp_parse as ftp_parse

if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -574,6 +575,12 @@ def supports_mlst(self):
"""bool: whether the server supports MLST feature."""
return "MLST" in self.features

@property
def supports_mdtm(self):
# type: () -> bool
"""bool: whether the server supports the MDTM feature."""
return "MDTM" in self.features

def create(self, path, wipe=False):
# type: (Text, bool) -> bool
_path = self.validatepath(path)
Expand Down Expand Up @@ -669,25 +676,6 @@ def getinfo(self, path, namespaces=None):
}
)

if "modified" in namespaces:
if "details" in namespaces:
warnings.warn(
"FTPFS.getinfo called with both 'modified' and 'details'"
" namespace. The former will be ignored.",
UserWarning,
)
else:
with self._lock:
with ftp_errors(self, path=path):
cmd = "MDTM " + _encode(
self.validatepath(path), self.ftp.encoding
)
response = self.ftp.sendcmd(cmd)
modified_info = {
"modified": self._parse_ftp_time(response.split()[1])
}
return Info({"modified": modified_info})

if self.supports_mlst:
with self._lock:
with ftp_errors(self, path=path):
Expand Down Expand Up @@ -716,6 +704,18 @@ def getmeta(self, namespace="standard"):
_meta["supports_mtime"] = "MDTM" in self.features
return _meta

def getmodified(self, path):
# type: (Text) -> Optional[datetime]
if self.supports_mdtm:
_path = self.validatepath(path)
with self._lock:
with ftp_errors(self, path=path):
cmd = "MDTM " + _encode(_path, self.ftp.encoding)
response = self.ftp.sendcmd(cmd)
mtime = self._parse_ftp_time(response.split()[1])
return epoch_to_datetime(mtime)
return super().getmodified(self, path)

def listdir(self, path):
# type: (Text) -> List[Text]
_path = self.validatepath(path)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_ftpfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ def test_getinfo_modified(self):
self.assertIn("MDTM", self.fs.features)
self.fs.create("bar")
mtime_detail = self.fs.getinfo("bar", ("basic", "details")).modified
mtime_modified = self.fs.getinfo("bar", ("modified",)).modified
mtime_modified = self.fs.getmodified("bar")
print(mtime_detail, mtime_modified)
Comment thread
althonos marked this conversation as resolved.
Outdated
# Microsecond and seconds might not actually be supported by all
# FTP commands, so we strip them before comparing if it looks
# like at least one of the two values does not contain them.
Expand Down