Skip to content

Commit 9b432a2

Browse files
author
atollk
committed
Fixed OSFS.copy(..., preserve_time=True).
1 parent e678957 commit 9b432a2

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

fs/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import six
2323

2424
from . import copy, errors, fsencode, iotools, move, tools, walk, wildcard
25-
from .copy import copy_cmtime
25+
from .copy import copy_mtime
2626
from .glob import BoundGlobber
2727
from .mode import validate_open_mode
2828
from .path import abspath, join, normpath
@@ -426,7 +426,7 @@ def copy(
426426
with closing(self.open(src_path, "rb")) as read_file:
427427
# FIXME(@althonos): typing complains because open return IO
428428
self.upload(dst_path, read_file) # type: ignore
429-
copy_cmtime(self, src_path, self, dst_path)
429+
copy_mtime(self, src_path, self, dst_path)
430430

431431
def copydir(
432432
self,
@@ -1155,7 +1155,7 @@ def move(self, src_path, dst_path, overwrite=False, preserve_time=False):
11551155
with self.open(src_path, "rb") as read_file:
11561156
# FIXME(@althonos): typing complains because open return IO
11571157
self.upload(dst_path, read_file) # type: ignore
1158-
copy_cmtime(self, src_path, self, dst_path)
1158+
copy_mtime(self, src_path, self, dst_path)
11591159
self.remove(src_path)
11601160

11611161
def open(

fs/copy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def copy_file(
159159
else:
160160
with _src_fs.openbin(src_path) as read_file:
161161
_dst_fs.upload(dst_path, read_file)
162-
copy_cmtime(_src_fs, src_path, _dst_fs, dst_path)
162+
copy_mtime(_src_fs, src_path, _dst_fs, dst_path)
163163

164164

165165
def copy_file_internal(
@@ -199,7 +199,7 @@ def copy_file_internal(
199199
with src_fs.openbin(src_path) as read_file:
200200
dst_fs.upload(dst_path, read_file)
201201

202-
copy_cmtime(src_fs, src_path, dst_fs, dst_path)
202+
copy_mtime(src_fs, src_path, dst_fs, dst_path)
203203

204204

205205
def copy_file_if_newer(
@@ -445,7 +445,7 @@ def dst():
445445
on_copy(_src_fs, dir_path, _dst_fs, copy_path)
446446

447447

448-
def copy_cmtime(
448+
def copy_mtime(
449449
src_fs, # type: Union[FS, Text]
450450
src_path, # type: Text
451451
dst_fs, # type: Union[FS, Text]

fs/osfs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from .mode import Mode, validate_open_mode
5050
from .errors import FileExpected, NoURL
5151
from ._url_tools import url_quote
52+
from .copy import copy_mtime
5253

5354
if typing.TYPE_CHECKING:
5455
from typing import (
@@ -452,6 +453,8 @@ def copy(self, src_path, dst_path, overwrite=False, preserve_time=False):
452453
while sent > 0:
453454
sent = sendfile(fd_dst, fd_src, offset, maxsize)
454455
offset += sent
456+
if preserve_time:
457+
copy_mtime(self, src_path, self, dst_path)
455458
except OSError as e:
456459
# the error is not a simple "sendfile not supported" error
457460
if e.errno not in self._sendfile_error_codes:

tests/test_osfs.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,9 @@ def test_expand_vars(self):
100100
def test_copy_preserve_time(self):
101101
self.fs.makedir("foo")
102102
self.fs.makedir("bar")
103-
now = time.time() - 10000
104-
if not self.fs.create("foo/file.txt"):
105-
raw_info = {"details": {"accessed": now, "modified": now}}
106-
self.fs.setinfo("foo/file.txt", raw_info)
103+
self.fs.create("foo/file.txt")
104+
raw_info = {"details": {"modified": time.time() - 10000}}
105+
self.fs.setinfo("foo/file.txt", raw_info)
107106

108107
namespaces = ("details", "modified")
109108
src_info = self.fs.getinfo("foo/file.txt", namespaces)

0 commit comments

Comments
 (0)