Ensure that the directories exist

If we create our temporary directory structure for our files, we need
to ensure that all the directories (including the ones in the filename)
exist before we copy the contents to that location.
This commit is contained in:
Ian Cordasco 2016-06-16 06:29:04 -05:00
parent 27eb975411
commit 07101231d9
No known key found for this signature in database
GPG key ID: 656D3395E4A9791A

View file

@ -116,6 +116,8 @@ def copy_file_to(destination_directory, filepath, contents):
directory, filename = os.path.split(os.path.abspath(filepath))
temporary_directory = make_temporary_directory_from(destination_directory,
directory)
if not os.path.exists(temporary_directory):
os.makedirs(temporary_directory)
temporary_filepath = os.path.join(temporary_directory, filename)
with open(temporary_filepath, 'wb') as fd:
fd.write(contents)