@@ -188,11 +188,12 @@ def querybuilder():
188188 }
189189
190190 # Handle temporary directory configuration
191+ tmp_prefix = '.aiida-export-'
191192 if tmp_dir is not None :
192193 tmp_dir = Path (tmp_dir )
193194 if not tmp_dir .exists ():
194- msg = f"Specified temporary directory '{ tmp_dir } ' does not exist"
195- raise ArchiveExportError ( msg )
195+ EXPORT_LOGGER . warning ( f"Specified temporary directory '{ tmp_dir } ' doesn't exist. Creating it." )
196+ tmp_dir . mkdir ( parents = False )
196197 if not tmp_dir .is_dir ():
197198 msg = f"Specified temporary directory '{ tmp_dir } ' is not a directory"
198199 raise ArchiveExportError (msg )
@@ -201,11 +202,10 @@ def querybuilder():
201202 if not os .access (tmp_dir , os .W_OK | os .X_OK ):
202203 msg = f"Specified temporary directory '{ tmp_dir } ' is not writable"
203204 raise ArchiveExportError (msg )
204- tmp_prefix = None # Use default tempfile prefix
205+
205206 else :
206207 # Create temporary directory in the same folder as the output file
207208 tmp_dir = filename .parent
208- tmp_prefix = '.aiida-export-'
209209
210210 initial_summary = get_init_summary (
211211 archive_version = archive_format .latest_version ,
@@ -311,7 +311,9 @@ def querybuilder():
311311 # Create and open the archive for writing.
312312 # We create in a temp dir then move to final place at end,
313313 # so that the user cannot end up with a half written archive on errors
314+
314315 try :
316+ tmp_dir .mkdir (parents = True , exist_ok = True )
315317 with tempfile .TemporaryDirectory (dir = tmp_dir , prefix = tmp_prefix ) as tmpdir :
316318 tmp_filename = Path (tmpdir ) / 'export.zip'
317319 with archive_format .open (tmp_filename , mode = 'x' , compression = compression ) as writer :
@@ -408,7 +410,9 @@ def transform(d):
408410 f'Consider using --tmp-dir to specify a location with more available space.'
409411 )
410412 raise ArchiveExportError (msg ) from e
411- raise ArchiveExportError (f'Failed to create temporary directory: { e } ' ) from e
413+
414+ msg = f'Failed to create temporary directory: { e } '
415+ raise ArchiveExportError (msg ) from e
412416
413417 EXPORT_LOGGER .report ('Archive created successfully' )
414418
0 commit comments