Skip to content

Fix preserving modification times on same-filesystem moves - #611

Open
Hugohong258 wants to merge 1 commit into
PyFilesystem:masterfrom
Hugohong258:fix-preserve-time-for-moves
Open

Hugohong258 wants to merge 1 commit into
PyFilesystem:masterfrom
Hugohong258:fix-preserve-time-for-moves

Conversation

@Hugohong258

Copy link
Copy Markdown

Type of changes

  • Bug fix

Checklist

  • I've run the latest black with default args on new code. (Checked with black 22.3.0, the version pinned in the project configuration.)
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @PyFilesystem/maintainers may be pedantic in the code review.

Description

Fixes #558. Moving a file within the same filesystem with preserve_time=True can raise ResourceNotFound after the original path has already been renamed. MemoryFS has the same problem when moving a directory.

A successful filesystem rename retains the file's modification time, and MemoryFS moves the existing entry with its timestamps intact. Avoid reading the old path in those cases; the copy-based fallback still copies the timestamp before removing the source. Regression tests cover direct and helper moves, destination replacement, and a MemoryFS directory with a child.

Thanks to @mj0nez for reporting the bug and the earlier investigation in #559.

Validation

  • Windows, CPython 3.9.25: python -m pytest tests/test_move.py -q (26 passed; 10 existing deprecation warnings).
  • Black 22.3.0 --check and the project flake8 configuration passed on the three changed Python files.
  • Linux, CPython 3.14.4: the same module had 20 passing tests and 6 failures in existing tests using the removed unittest.TestCase.assertEquals alias; the full test matrix was not run.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ResourceNotFound - moving files on the same filesystem with preserve_time=True

1 participant