Skip to content

Commit

Permalink
Avoid a crash when output dir exists
Browse files Browse the repository at this point in the history
  • Loading branch information
bouweandela committed Oct 14, 2022
1 parent 0f5bda8 commit 416b028
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions esmvalcore/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,17 @@ def run(self,
cfg = read_config_user_file(config_file, recipe.stem, kwargs)

# Create run dir
if os.path.exists(cfg['run_dir']):
print("ERROR: run_dir {} already exists, aborting to "
"prevent data loss".format(cfg['output_dir']))
run_dir = Path(cfg['run_dir'])
if run_dir.exists():
suffix = 1
run_dir = Path(f"{run_dir}-{suffix}")
while run_dir.exists():
suffix += 1
run_dir = Path(f"{str(run_dir).rsplit('-', 1)[0]}-{suffix}")
if suffix > 1000:
print("ERROR: run_dir {} already exists, aborting to "
"prevent data loss".format(cfg['output_dir']))
cfg['run_dir'] = str(run_dir)
os.makedirs(cfg['run_dir'])

# configure logging
Expand Down

0 comments on commit 416b028

Please sign in to comment.