From: Philipp Gesang Date: Thu, 5 Jul 2018 06:53:06 +0000 (+0200) Subject: drop os.exists() before makedirs() X-Git-Tag: v2.2~6^2~4 X-Git-Url: http://developer.intra2net.com/git/?p=python-delta-tar;a=commitdiff_plain;h=37ab0f577fd7cef2922c99d6fd91f22100075476 drop os.exists() before makedirs() os.makedirs() has proper EEXIST handling builtin. Checking with ``os.exists()`` is both redundant and inherently racy. --- diff --git a/deltatar/deltatar.py b/deltatar/deltatar.py index 057c98f..161008c 100644 --- a/deltatar/deltatar.py +++ b/deltatar/deltatar.py @@ -655,8 +655,7 @@ class DeltaTar(object): raise Exception('Source path "%s" is not readable' % source_path) # try to create backup path if needed - if not os.path.exists(backup_path): - os.makedirs(backup_path) + os.makedirs(backup_path, exist_ok=True) if not os.access(backup_path, os.W_OK): raise Exception('Backup path "%s" is not writeable' % backup_path) @@ -825,8 +824,7 @@ class DeltaTar(object): raise Exception('Index path "%s" is not readable' % previous_index_path) # try to create backup path if needed - if not os.path.exists(backup_path): - os.makedirs(backup_path) + os.makedirs(backup_path, exist_ok=True) if not os.access(backup_path, os.W_OK): raise Exception('Backup path "%s" is not writeable' % backup_path) @@ -1424,8 +1422,7 @@ class DeltaTar(object): raise Exception('Index path "%s" is not readable' % index) # try to create backup path if needed - if not os.path.exists(target_path): - os.makedirs(target_path) + os.makedirs(target_path, exist_ok=True) # make backup_tar_path absolute so that iterate_tar_path works fine if backup_tar_path and not os.path.isabs(backup_tar_path): @@ -1787,8 +1784,7 @@ class RestoreHelper(object): # to preserve parent directory mtime, we save it parent_dir = os.path.dirname(upath) or os.getcwd() - if not os.path.exists(parent_dir): - os.makedirs(parent_dir) + os.makedirs(parent_dir, exist_ok=True) parent_dir_mtime = int(os.stat(parent_dir).st_mtime) # if path is found in the newest index as to be snapshotted, deal with it