-
-
Notifications
You must be signed in to change notification settings - Fork 180
Optimize move.move_file
for moving files between different OSFS instances.
#523
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
Merged
althonos
merged 42 commits into
PyFilesystem:master
from
tfeldmann:move_file-optimization
May 2, 2022
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
db837c5
add optimization to move
tfeldmann d6db460
update contributors
tfeldmann 43dc890
add test
tfeldmann cb49b6e
optimization not dependent of OSFS anymore
tfeldmann 1f7b0ff
Merge branch 'master' into move_file-optimization
tfeldmann 448f15f
remove unneeded import
tfeldmann 68846ce
lock src and dst for move operation
tfeldmann 003e1b7
handle ValueError
tfeldmann fa1803b
fix unbound var
tfeldmann 86adaa8
set "read_only": True in `WrapReadOnly.getmeta()`
tfeldmann 014123b
handle ro FSs in move_file optimization
tfeldmann 14d4fa2
add test for two different MemFS instances
tfeldmann a97c0c3
support FS URLs
tfeldmann bbe4389
clear use of fs url instead of str
tfeldmann 69022aa
add test for read-only sources
tfeldmann 545e016
more tests for read only sources
tfeldmann fd577df
clarify fallthrough and add writeable=True
tfeldmann 4edb1e0
cleanup destination if move fails
tfeldmann 20203d9
update changelog
tfeldmann ad7a970
raise exc in mange_fs if fs is not writeable
tfeldmann 1267194
don't run tests twice in parameterized_class
tfeldmann b0963bf
remove unneeded import
tfeldmann 4a102ce
update changelog
tfeldmann 763efc2
rename test case
tfeldmann e490452
formatting
tfeldmann 0c02f53
add python2.7 commonpath backport
tfeldmann 9be0381
fix path in ResourceReadOnly exception
tfeldmann baf7019
test_move cleanup
tfeldmann 69d1906
check time on if self.preserve_time is set
tfeldmann 7993af0
update changelog wording
tfeldmann 9cfc5dd
revert import order
tfeldmann 54d3374
ignore flake8 C401 in _pathcompat
tfeldmann c051f23
fix codestyle and typecheck errors
tfeldmann a549250
removed duplicated test code
tfeldmann 44cbe31
add `cleanup_dest_on_error` in `move_file`
tfeldmann 696c4ca
use non-overlapping osfs urls
tfeldmann 891d1fc
use OSFS instead of fs_open, rename cleanup_dst_on_error param
tfeldmann 4d80b22
fix `supports_rename` in `WrapReadOnly`
tfeldmann 78f6696
cleanup test_move filenames
tfeldmann 46fbc71
Fix circular import between `fs.base`, `fs.osfs` and `fs.move`
althonos 5675f84
cleanup and docs
tfeldmann da33922
test `src` first, then `dst`
tfeldmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
except ImportError: | ||
import mock | ||
|
||
from parameterized import parameterized_class | ||
from parameterized import parameterized, parameterized_class | ||
|
||
|
||
import fs.move | ||
|
@@ -80,10 +80,10 @@ def test_move_dir(self): | |
|
||
fs.move.move_dir(src_fs, "/foo", dst_fs, "/", preserve_time=self.preserve_time) | ||
|
||
self.assertTrue(dst_fs.isdir("bar")) | ||
self.assertTrue(dst_fs.isfile("bar/baz.txt")) | ||
self.assertFalse(src_fs.exists("foo")) | ||
self.assertTrue(src_fs.isfile("test.txt")) | ||
self.assertTrue(dst_fs.isdir("bar")) | ||
self.assertTrue(dst_fs.isfile("bar/baz.txt")) | ||
|
||
if self.preserve_time: | ||
dst_file2_info = dst_fs.getinfo("bar/baz.txt", namespaces) | ||
|
@@ -104,16 +104,16 @@ def test_move_file_fs_urls(self): | |
# create a temp dir to work on | ||
with open_fs("temp://") as tmp: | ||
path = tmp.getsyspath("/") | ||
subdir_src = tmp.makedir("subdir_src") | ||
subdir_src.writetext("file.txt", "Content") | ||
tmp.makedir("subdir_src") | ||
tmp.writetext("subdir_src/file.txt", "Content") | ||
tmp.makedir("subdir_dst") | ||
fs.move.move_file( | ||
"osfs://" + join(path, "subdir_src"), | ||
"file.txt", | ||
"osfs://" + join(path, "subdir_dst"), | ||
"target.txt", | ||
) | ||
self.assertFalse(subdir_src.exists("file.txt")) | ||
self.assertFalse(tmp.exists("subdir_src/file.txt")) | ||
self.assertEqual(tmp.readtext("subdir_dst/target.txt"), "Content") | ||
|
||
def test_move_file_same_fs_read_only_source(self): | ||
|
@@ -124,10 +124,10 @@ def test_move_file_same_fs_read_only_source(self): | |
dst = tmp.makedir("sub") | ||
with self.assertRaises(ResourceReadOnly): | ||
fs.move.move_file(src, "file.txt", dst, "target_file.txt") | ||
self.assertTrue(src.exists("file.txt")) | ||
self.assertFalse( | ||
dst.exists("target_file.txt"), "file should not have been copied over" | ||
) | ||
self.assertTrue(src.exists("file.txt")) | ||
|
||
def test_move_file_read_only_mem_source(self): | ||
with open_fs("mem://") as src, open_fs("mem://") as dst: | ||
|
@@ -136,40 +136,35 @@ def test_move_file_read_only_mem_source(self): | |
src_ro = read_only(src) | ||
with self.assertRaises(ResourceReadOnly): | ||
fs.move.move_file(src_ro, "file.txt", dst_sub, "target.txt") | ||
self.assertTrue(src.exists("file.txt")) | ||
self.assertFalse( | ||
dst_sub.exists("target.txt"), "file should not have been copied over" | ||
) | ||
self.assertTrue(src.exists("file.txt")) | ||
|
||
def test_move_file_read_only_mem_dest(self): | ||
with open_fs("mem://") as src, open_fs("mem://") as dst: | ||
src.writetext("file.txt", "Content") | ||
dst_ro = read_only(dst) | ||
with self.assertRaises(ResourceReadOnly): | ||
fs.move.move_file(src, "file.txt", dst_ro, "target.txt") | ||
self.assertTrue(src.exists("file.txt")) | ||
self.assertFalse( | ||
dst_ro.exists("target.txt"), "file should not have been copied over" | ||
) | ||
self.assertTrue(src.exists("file.txt")) | ||
|
||
def test_move_file_cleanup_on_error(self): | ||
with open_fs("mem://") as src, open_fs("mem://") as dst: | ||
src.writetext("file.txt", "Content") | ||
with mock.patch.object(src, "remove") as mck: | ||
mck.side_effect = FSError | ||
with self.assertRaises(FSError): | ||
fs.move.move_file(src, "file.txt", dst, "target.txt") | ||
self.assertTrue(src.exists("file.txt")) | ||
self.assertFalse(dst.exists("target.txt")) | ||
|
||
def test_move_file_no_cleanup_on_error(self): | ||
@parameterized.expand([(True,), (False,)]) | ||
def test_move_file_cleanup_on_error(self, cleanup): | ||
with open_fs("mem://") as src, open_fs("mem://") as dst: | ||
src.writetext("file.txt", "Content") | ||
with mock.patch.object(src, "remove") as mck: | ||
mck.side_effect = FSError | ||
with self.assertRaises(FSError): | ||
fs.move.move_file( | ||
src, "file.txt", dst, "target.txt", cleanup_dst_on_error=False | ||
src, | ||
"file.txt", | ||
dst, | ||
"target.txt", | ||
cleanup_dst_on_error=cleanup, | ||
) | ||
self.assertTrue(src.exists("file.txt")) | ||
self.assertTrue(dst.exists("target.txt")) | ||
self.assertEqual(not dst.exists("target.txt"), cleanup) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be marginally more readable as self.assertEqual(dst.exists("target.txt"), not cleanup) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.