Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Lib/shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def _copytree(entries, src, dst, symlinks, ignore, copy_function,
dirs_exist_ok=dirs_exist_ok)
else:
# Will raise a SpecialFileError for unsupported file types
copy_function(srcentry, dstname)
copy_function(srcobj, dstname)
# catch the Error from the recursive copytree so that we can
# continue with other files
except Error as err:
Expand Down
18 changes: 18 additions & 0 deletions Lib/test/test_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,24 @@ def test_copytree_winerror(self, mock_patch):
with self.assertRaises(shutil.Error):
shutil.copytree(src_dir, dst_dir)

def test_copytree_custom_copy_function(self):
# See: https://bugs.python.org/issue35648
def custom_cpfun(a, b):
flag.append(None)
self.assertIsInstance(a, str)
self.assertIsInstance(b, str)
self.assertEqual(a, os.path.join(src, 'foo'))
self.assertEqual(b, os.path.join(dst, 'foo'))

flag = []
src = tempfile.mkdtemp()
dst = tempfile.mktemp()
self.addCleanup(shutil.rmtree, src)
with open(os.path.join(src, 'foo'), 'w') as f:
f.close()
shutil.copytree(src, dst, copy_function=custom_cpfun)
self.assertEqual(len(flag), 1)

@unittest.skipIf(os.name == 'nt', 'temporarily disabled on Windows')
@unittest.skipUnless(hasattr(os, 'link'), 'requires os.link')
def test_dont_copy_file_onto_link_to_itself(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shutil.copytree(copy_function=...) erroneously pass DirEntry instead of a
path string.