Skip to content

Commit 3065813

Browse files
author
atollk
committed
Fixes from code review.
1 parent 9c9f5c7 commit 3065813

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212

1313
- Added `fs.copy.copy_file_if`, `fs.copy.copy_dir_if`, and `fs.copy.copy_fs_if`.
1414
Closes [#458](https://github.com/PyFilesystem/pyfilesystem2/issues/458).
15+
- Added `fs.base.FS.getmodified`.
1516

1617
### Changed
1718

docs/source/interface.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The following is a complete list of methods on PyFilesystem objects.
2020
* :meth:`~fs.base.FS.getdetails` Get details info namespace for a resource.
2121
* :meth:`~fs.base.FS.getinfo` Get info regarding a file or directory.
2222
* :meth:`~fs.base.FS.getmeta` Get meta information for a resource.
23+
* :meth:`~fs.base.FS.getmodified` Get info regarding the last modified time of a resource.
2324
* :meth:`~fs.base.FS.getospath` Get path with encoding expected by the OS.
2425
* :meth:`~fs.base.FS.getsize` Get the size of a file.
2526
* :meth:`~fs.base.FS.getsyspath` Get the system path of a resource, if one exists.

fs/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ def getmeta(self, namespace="standard"):
754754
supports_rename `True` if this filesystem supports an
755755
`os.rename` operation.
756756
supports_mtime `True` if this filesystem supports a native
757-
operation to retreive the "last modified" time.
757+
operation to retrieve the "last modified" time.
758758
=================== ============================================
759759
760760
Most builtin filesystems will provide all these keys, and third-

fs/ftpfs.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import socket
1313
import threading
1414
import typing
15+
import warnings
1516
from collections import OrderedDict
1617
from contextlib import contextmanager
1718
from ftplib import FTP
@@ -669,16 +670,23 @@ def getinfo(self, path, namespaces=None):
669670
)
670671

671672
if "modified" in namespaces:
672-
if "basic" in namespaces or "details" in namespaces:
673-
raise ValueError(
674-
'Cannot use the "modified" namespace in combination with others.'
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,
675678
)
676-
with self._lock:
677-
with ftp_errors(self, path=path):
678-
cmd = "MDTM " + _encode(self.validatepath(path), self.ftp.encoding)
679-
response = self.ftp.sendcmd(cmd)
680-
modified_info = {"modified": self._parse_ftp_time(response.split()[1])}
681-
return Info({"modified": modified_info})
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})
682690

683691
if self.supports_mlst:
684692
with self._lock:

tests/test_memoryfs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ def test_copy_preserve_time(self):
7272
self.fs.makedir("bar")
7373
self.fs.touch("foo/file.txt")
7474

75-
src_info = self.fs.getmodified("foo/file.txt")
75+
src_datetime = self.fs.getmodified("foo/file.txt")
7676

7777
self.fs.copy("foo/file.txt", "bar/file.txt", preserve_time=True)
7878
self.assertTrue(self.fs.exists("bar/file.txt"))
7979

80-
dst_info = self.fs.getmodified("bar/file.txt")
81-
self.assertEqual(dst_info, src_info)
80+
dst_datetime = self.fs.getmodified("bar/file.txt")
81+
self.assertEqual(dst_datetime, src_datetime)
8282

8383

8484
class TestMemoryFile(unittest.TestCase):

0 commit comments

Comments
 (0)