Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix file move time preservation (#558) #559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mj0nez wants to merge 9 commits into PyFilesystem:master
base: master
Choose a base branch
Loading
from mj0nez:fix-file-move-time-preservation
Open
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
Prev Previous commit
Next Next commit
fixed FS.move to allow correct time preservation
  • Loading branch information
mj0nez committed Dec 28, 2022
commit 49dfce72966cfcd788d45b4a7b1d370f571e643c
19 changes: 16 additions & 3 deletions fs/base.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from functools import partial, wraps

from . import copy, errors, fsencode, glob, iotools, tools, walk, wildcard
from .copy import copy_modified_time
from .copy import copy_modified_time, read_modified_time, update_details_namespace
from .glob import BoundGlobber
from .mode import validate_open_mode
from .path import abspath, isbase, join, normpath
Expand Down Expand Up @@ -1187,14 +1187,27 @@ def move(self, src_path, dst_path, overwrite=False, preserve_time=False):
except errors.NoSysPath: # pragma: no cover
pass
else:
# Without preserving the modification time we can rename
# the file's path.
if not preserve_time:
try:
os.rename(src_sys_path, dst_sys_path)
except OSError:
pass
else:
return

# read the modification before moving the file
modification_details = read_modified_time(self, _src_path)
try:
os.rename(src_sys_path, dst_sys_path)
except OSError:
pass
else:
if preserve_time:
copy_modified_time(self, _src_path, self, _dst_path)
# update the meta info
update_details_namespace(self, _dst_path, modification_details)
return

with self._lock:
with self.open(_src_path, "rb") as read_file:
# FIXME(@althonos): typing complains because open return IO
Expand Down

AltStyle によって変換されたページ (->オリジナル) /