2222import six
2323
2424from . import copy , errors , fsencode , iotools , move , tools , walk , wildcard
25+ from .copy import copy_modified_time
2526from .glob import BoundGlobber
2627from .mode import validate_open_mode
2728from .path import abspath , join , normpath
@@ -393,15 +394,23 @@ def close(self):
393394 """
394395 self ._closed = True
395396
396- def copy (self , src_path , dst_path , overwrite = False ):
397- # type: (Text, Text, bool) -> None
397+ def copy (
398+ self ,
399+ src_path , # type: Text
400+ dst_path , # type: Text
401+ overwrite = False , # type: bool
402+ preserve_time = False , # type: bool
403+ ):
404+ # type: (...) -> None
398405 """Copy file contents from ``src_path`` to ``dst_path``.
399406
400407 Arguments:
401408 src_path (str): Path of source file.
402409 dst_path (str): Path to destination file.
403410 overwrite (bool): If `True`, overwrite the destination file
404411 if it exists (defaults to `False`).
412+ preserve_time (bool): If `True`, try to preserve mtime of the
413+ resource (defaults to `False`).
405414
406415 Raises:
407416 fs.errors.DestinationExists: If ``dst_path`` exists,
@@ -417,16 +426,26 @@ def copy(self, src_path, dst_path, overwrite=False):
417426 with closing (self .open (src_path , "rb" )) as read_file :
418427 # FIXME(@althonos): typing complains because open return IO
419428 self .upload (dst_path , read_file ) # type: ignore
429+ if preserve_time :
430+ copy_modified_time (self , src_path , self , dst_path )
420431
421- def copydir (self , src_path , dst_path , create = False ):
422- # type: (Text, Text, bool) -> None
432+ def copydir (
433+ self ,
434+ src_path , # type: Text
435+ dst_path , # type: Text
436+ create = False , # type: bool
437+ preserve_time = False , # type: bool
438+ ):
439+ # type: (...) -> None
423440 """Copy the contents of ``src_path`` to ``dst_path``.
424441
425442 Arguments:
426443 src_path (str): Path of source directory.
427444 dst_path (str): Path to destination directory.
428445 create (bool): If `True`, then ``dst_path`` will be created
429446 if it doesn't exist already (defaults to `False`).
447+ preserve_time (bool): If `True`, try to preserve mtime of the
448+ resource (defaults to `False`).
430449
431450 Raises:
432451 fs.errors.ResourceNotFound: If the ``dst_path``
@@ -440,7 +459,7 @@ def copydir(self, src_path, dst_path, create=False):
440459 raise errors .ResourceNotFound (dst_path )
441460 if not self .getinfo (src_path ).is_dir :
442461 raise errors .DirectoryExpected (src_path )
443- copy .copy_dir (self , src_path , self , dst_path )
462+ copy .copy_dir (self , src_path , self , dst_path , preserve_time = preserve_time )
444463
445464 def create (self , path , wipe = False ):
446465 # type: (Text, bool) -> bool
@@ -1027,15 +1046,17 @@ def lock(self):
10271046 """
10281047 return self ._lock
10291048
1030- def movedir (self , src_path , dst_path , create = False ):
1031- # type: (Text, Text, bool) -> None
1049+ def movedir (self , src_path , dst_path , create = False , preserve_time = False ):
1050+ # type: (Text, Text, bool, bool ) -> None
10321051 """Move directory ``src_path`` to ``dst_path``.
10331052
10341053 Arguments:
10351054 src_path (str): Path of source directory on the filesystem.
10361055 dst_path (str): Path to destination directory.
10371056 create (bool): If `True`, then ``dst_path`` will be created
10381057 if it doesn't exist already (defaults to `False`).
1058+ preserve_time (bool): If `True`, try to preserve mtime of the
1059+ resources (defaults to `False`).
10391060
10401061 Raises:
10411062 fs.errors.ResourceNotFound: if ``dst_path`` does not exist,
@@ -1047,7 +1068,7 @@ def movedir(self, src_path, dst_path, create=False):
10471068 with self ._lock :
10481069 if not create and not self .exists (dst_path ):
10491070 raise errors .ResourceNotFound (dst_path )
1050- move .move_dir (self , src_path , self , dst_path )
1071+ move .move_dir (self , src_path , self , dst_path , preserve_time = preserve_time )
10511072
10521073 def makedirs (
10531074 self ,
@@ -1092,8 +1113,8 @@ def makedirs(
10921113 raise
10931114 return self .opendir (path )
10941115
1095- def move (self , src_path , dst_path , overwrite = False ):
1096- # type: (Text, Text, bool) -> None
1116+ def move (self , src_path , dst_path , overwrite = False , preserve_time = False ):
1117+ # type: (Text, Text, bool, bool ) -> None
10971118 """Move a file from ``src_path`` to ``dst_path``.
10981119
10991120 Arguments:
@@ -1102,6 +1123,8 @@ def move(self, src_path, dst_path, overwrite=False):
11021123 file will be written to.
11031124 overwrite (bool): If `True`, destination path will be
11041125 overwritten if it exists.
1126+ preserve_time (bool): If `True`, try to preserve mtime of the
1127+ resources (defaults to `False`).
11051128
11061129 Raises:
11071130 fs.errors.FileExpected: If ``src_path`` maps to a
@@ -1128,11 +1151,15 @@ def move(self, src_path, dst_path, overwrite=False):
11281151 except OSError :
11291152 pass
11301153 else :
1154+ if preserve_time :
1155+ copy_modified_time (self , src_path , self , dst_path )
11311156 return
11321157 with self ._lock :
11331158 with self .open (src_path , "rb" ) as read_file :
11341159 # FIXME(@althonos): typing complains because open return IO
11351160 self .upload (dst_path , read_file ) # type: ignore
1161+ if preserve_time :
1162+ copy_modified_time (self , src_path , self , dst_path )
11361163 self .remove (src_path )
11371164
11381165 def open (
0 commit comments