Author vlasenkoalexey
Recipients dstufft, eric.araujo, vlasenkoalexey
Date 2020-12-09.01:08:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1607476103.38.0.0125735789387.issue42605@roundup.psfhosted.org>
In-reply-to
Content
Minimal example:

import os
import shutil
from distutils import dir_util

shutil.rmtree('folder1')

os.makedirs('folder1/folder2/folder3/')
with open('folder1/folder2/folder3/data.txt', 'w') as fp:
    fp.write('hello')
    
print(os.path.exists('folder1/new_folder2')) # -> prints false
dir_util.copy_tree('folder1/folder2', 'folder1/new_folder2') # -> works

shutil.rmtree('folder1/new_folder2')
print(os.path.exists('folder1/new_folder2')) # -> prints false
dir_util.copy_tree('folder1/folder2', 'folder1/new_folder2') # -> crashes

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
/opt/conda/lib/python3.7/distutils/file_util.py in _copy_file_contents(src, dst, buffer_size)
     40         try:
---> 41             fdst = open(dst, 'wb')
     42         except OSError as e:

FileNotFoundError: [Errno 2] No such file or directory: 'folder1/new_folder2/folder3/data.txt'

dir_util caches folders it previously created in a static global variable _path_created which is a bad idea:
https://github.com/python/cpython/blob/master/Lib/distutils/dir_util.py
History
Date User Action Args
2020-12-09 01:08:23vlasenkoalexeysetrecipients: + vlasenkoalexey, eric.araujo, dstufft
2020-12-09 01:08:23vlasenkoalexeysetmessageid: <1607476103.38.0.0125735789387.issue42605@roundup.psfhosted.org>
2020-12-09 01:08:23vlasenkoalexeylinkissue42605 messages
2020-12-09 01:08:23vlasenkoalexeycreate