@@ -187,26 +187,6 @@ def querybuilder():
187187 name : traversal_rules .get (name , rule .default ) for name , rule in GraphTraversalRules .EXPORT .value .items ()
188188 }
189189
190- # Handle temporary directory configuration
191- tmp_prefix = '.aiida-export-'
192- if tmp_dir is not None :
193- tmp_dir = Path (tmp_dir )
194- if not tmp_dir .exists ():
195- EXPORT_LOGGER .warning (f"Specified temporary directory '{ tmp_dir } ' doesn't exist. Creating it." )
196- tmp_dir .mkdir (parents = False )
197- if not tmp_dir .is_dir ():
198- msg = f"Specified temporary directory '{ tmp_dir } ' is not a directory"
199- raise ArchiveExportError (msg )
200- # Check if directory is writable
201- # Taken from: https://stackoverflow.com/a/2113511
202- if not os .access (tmp_dir , os .W_OK | os .X_OK ):
203- msg = f"Specified temporary directory '{ tmp_dir } ' is not writable"
204- raise ArchiveExportError (msg )
205-
206- else :
207- # Create temporary directory in the same folder as the output file
208- tmp_dir = filename .parent
209-
210190 initial_summary = get_init_summary (
211191 archive_version = archive_format .latest_version ,
212192 outfile = filename ,
@@ -308,10 +288,29 @@ def querybuilder():
308288
309289 EXPORT_LOGGER .report (f'Creating archive with:\n { tabulate (count_summary )} ' )
310290
291+ # Handle temporary directory configuration
292+ tmp_prefix = '.aiida-export-'
293+ if tmp_dir is not None :
294+ tmp_dir = Path (tmp_dir )
295+ if not tmp_dir .exists ():
296+ EXPORT_LOGGER .warning (f"Specified temporary directory '{ tmp_dir } ' doesn't exist. Creating it." )
297+ tmp_dir .mkdir (parents = False )
298+ if not tmp_dir .is_dir ():
299+ msg = f"Specified temporary directory '{ tmp_dir } ' is not a directory"
300+ raise ArchiveExportError (msg )
301+ # Check if directory is writable
302+ # Taken from: https://stackoverflow.com/a/2113511
303+ if not os .access (tmp_dir , os .W_OK | os .X_OK ):
304+ msg = f"Specified temporary directory '{ tmp_dir } ' is not writable"
305+ raise ArchiveExportError (msg )
306+
307+ else :
308+ # Create temporary directory in the same folder as the output file
309+ tmp_dir = filename .parent
310+
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-
315314 try :
316315 tmp_dir .mkdir (parents = True , exist_ok = True )
317316 with tempfile .TemporaryDirectory (dir = tmp_dir , prefix = tmp_prefix ) as tmpdir :
0 commit comments