|
42 | 42 | from .path import basename
|
43 | 43 | from .path import normpath
|
44 | 44 | from .path import split
|
| 45 | +from .time import epoch_to_datetime |
45 | 46 | from . import _ftp_parse as ftp_parse
|
46 | 47 |
|
47 | 48 | if typing.TYPE_CHECKING:
|
@@ -574,6 +575,12 @@ def supports_mlst(self):
|
574 | 575 | """bool: whether the server supports MLST feature."""
|
575 | 576 | return "MLST" in self.features
|
576 | 577 |
|
| 578 | + @property |
| 579 | + def supports_mdtm(self): |
| 580 | + # type: () -> bool |
| 581 | + """bool: whether the server supports the MDTM feature.""" |
| 582 | + return "MDTM" in self.features |
| 583 | + |
577 | 584 | def create(self, path, wipe=False):
|
578 | 585 | # type: (Text, bool) -> bool
|
579 | 586 | _path = self.validatepath(path)
|
@@ -669,25 +676,6 @@ def getinfo(self, path, namespaces=None):
|
669 | 676 | }
|
670 | 677 | )
|
671 | 678 |
|
672 |
| - if "modified" in namespaces: |
673 |
| - if "details" in namespaces: |
674 |
| - warnings.warn( |
675 |
| - "FTPFS.getinfo called with both 'modified' and 'details'" |
676 |
| - " namespace. The former will be ignored.", |
677 |
| - UserWarning, |
678 |
| - ) |
679 |
| - else: |
680 |
| - with self._lock: |
681 |
| - with ftp_errors(self, path=path): |
682 |
| - cmd = "MDTM " + _encode( |
683 |
| - self.validatepath(path), self.ftp.encoding |
684 |
| - ) |
685 |
| - response = self.ftp.sendcmd(cmd) |
686 |
| - modified_info = { |
687 |
| - "modified": self._parse_ftp_time(response.split()[1]) |
688 |
| - } |
689 |
| - return Info({"modified": modified_info}) |
690 |
| - |
691 | 679 | if self.supports_mlst:
|
692 | 680 | with self._lock:
|
693 | 681 | with ftp_errors(self, path=path):
|
@@ -716,6 +704,18 @@ def getmeta(self, namespace="standard"):
|
716 | 704 | _meta["supports_mtime"] = "MDTM" in self.features
|
717 | 705 | return _meta
|
718 | 706 |
|
| 707 | + def getmodified(self, path): |
| 708 | + # type: (Text) -> Optional[datetime] |
| 709 | + if self.supports_mdtm: |
| 710 | + _path = self.validatepath(path) |
| 711 | + with self._lock: |
| 712 | + with ftp_errors(self, path=path): |
| 713 | + cmd = "MDTM " + _encode(_path, self.ftp.encoding) |
| 714 | + response = self.ftp.sendcmd(cmd) |
| 715 | + mtime = self._parse_ftp_time(response.split()[1]) |
| 716 | + return epoch_to_datetime(mtime) |
| 717 | + return super().getmodified(self, path) |
| 718 | + |
719 | 719 | def listdir(self, path):
|
720 | 720 | # type: (Text) -> List[Text]
|
721 | 721 | _path = self.validatepath(path)
|
|
0 commit comments