@@ -292,11 +292,11 @@ def __init__(self,
292292 if not node .status ():
293293 raise BackupException ('Node must be running' )
294294
295- # set default arguments
295+ # Set default arguments
296296 username = username or default_username ()
297297 base_dir = base_dir or tempfile .mkdtemp ()
298298
299- # create directory if needed
299+ # Create directory if needed
300300 if base_dir and not os .path .exists (base_dir ):
301301 os .makedirs (base_dir )
302302
@@ -350,7 +350,7 @@ def _prepare_dir(self, destroy):
350350 else :
351351 base_dir = self .base_dir
352352
353- # update value
353+ # Update value
354354 self .available = available
355355
356356 return base_dir
@@ -370,12 +370,15 @@ def spawn_primary(self, name, destroy=True, use_logging=False):
370370
371371 base_dir = self ._prepare_dir (destroy )
372372
373- # build a new PostgresNode
373+ # Build a new PostgresNode
374374 node = PostgresNode (name = name ,
375375 base_dir = base_dir ,
376376 master = self .original_node ,
377377 use_logging = use_logging )
378378
379+ # New nodes should always remove dir tree
380+ node .should_rm_dirs = True
381+
379382 node .append_conf ("postgresql.conf" , "\n " )
380383 node .append_conf ("postgresql.conf" , "port = {}" .format (node .port ))
381384
@@ -1149,13 +1152,14 @@ def _execute_utility(util, args, logfile, write_to_pipe=True):
11491152 util: utility to be executed (str).
11501153 args: arguments for utility (list).
11511154 logfile: stores stdout and stderr (str).
1155+ write_to_pipe: do we care about stdout?
11521156
11531157 Returns:
11541158 stdout of executed utility.
11551159 """
11561160
1157- with open ( logfile , "a" ) as file_out , \
1158- open (os .devnull , "w" ) as devnull : # hack for 2.7
1161+ # we can't use subprocess.DEVNULL on 2.7
1162+ with open (os .devnull , "w" ) as devnull :
11591163
11601164 # choose file according to options
11611165 stdout_file = subprocess .PIPE if write_to_pipe else devnull
@@ -1169,10 +1173,16 @@ def _execute_utility(util, args, logfile, write_to_pipe=True):
11691173 out , _ = process .communicate ()
11701174 out = '' if not out else out .decode ('utf-8' )
11711175
1172- # write new log entry
1173- file_out .write ('' .join (map (lambda x : str (x ) + ' ' , [util ] + args )))
1174- file_out .write ('\n ' )
1175- file_out .write (out )
1176+ # write new log entry if possible
1177+ try :
1178+ with open (logfile , "a" ) as file_out :
1179+ # write util name + args
1180+ file_out .write ('' .join (map (lambda x : str (x ) + ' ' ,
1181+ [util ] + args )))
1182+ file_out .write ('\n ' )
1183+ file_out .write (out )
1184+ except FileNotFoundError :
1185+ pass
11761186
11771187 if process .returncode :
11781188 error_text = (
0 commit comments