From dec05c6d4e255a8ba34db83f8a0077b3125efa58 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 6 Nov 2014 17:41:51 +0100 Subject: [PATCH] ensure the destination path exists before moving --- webservice/bam/application/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/webservice/bam/application/__init__.py b/webservice/bam/application/__init__.py index cc179f0..a28fdf5 100644 --- a/webservice/bam/application/__init__.py +++ b/webservice/bam/application/__init__.py @@ -242,9 +242,13 @@ class FileAPI(Resource): import shutil for src_file_path, dst_file_path in path_remap.items(): assert(os.path.exists(os.path.join(extract_tmp_dir, src_file_path))) - shutil.move( - os.path.join(extract_tmp_dir, src_file_path), - os.path.join(project.repository_path, dst_file_path)) + + src_file_path_abs = os.path.join(extract_tmp_dir, src_file_path) + dst_file_path_abs = os.path.join(project.repository_path, dst_file_path) + + os.makedirs(os.path.dirname(dst_file_path_abs), exist_ok=True) + + shutil.move(src_file_path_abs, dst_file_path_abs) # TODO, dry run commit (using commit message) # Seems not easily possible with SVN, so we might just smartly use svn status @@ -254,7 +258,7 @@ class FileAPI(Resource): # We parse the svn status xml output root = xml.etree.ElementTree.fromstring(result) - + # Loop throught every entry reported by the svn status command for e in root.iter('entry'): file_path = e.attrib['path']