From 49fc8be3ba82e16ab0124bca35a2a24ce7da37a4 Mon Sep 17 00:00:00 2001 From: Anmol Singh Jaggi Date: Sat, 28 Oct 2017 14:18:48 +0530 Subject: [PATCH 1/3] Fix race condition while creating directories --- src/gmv/gmvault_utils.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/gmv/gmvault_utils.py b/src/gmv/gmvault_utils.py index 9503f98a..2def6231 100755 --- a/src/gmv/gmvault_utils.py +++ b/src/gmv/gmvault_utils.py @@ -395,15 +395,17 @@ def contains_any(string, char_set): return 1 in [c in string for c in char_set] def makedirs(a_path): - """ my own version of makedir """ - - if os.path.isdir(a_path): - # it already exists so return - return - elif os.path.isfile(a_path): - raise OSError("a file with the same name as the desired dir, '%s', already exists."%(a_path)) - - os.makedirs(a_path) + """ + Create all the intermediate directories in a path. + Similar to the `mkdir -p` command. + """ + try: + os.makedirs(a_path) + except OSError as exc: # Python >2.5 + if exc.errno == errno.EEXIST and os.path.isdir(a_path): + pass + else: + raise def __rmgeneric(path, __func__): """ private function that is part of delete_all_under """ From 8f1a1eedd4589db337a30c5165bc83103bdd932d Mon Sep 17 00:00:00 2001 From: Anmol Singh Jaggi Date: Sat, 28 Oct 2017 14:18:48 +0530 Subject: [PATCH 2/3] Fix race condition while creating directories --- src/gmv/gmvault_utils.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/gmv/gmvault_utils.py b/src/gmv/gmvault_utils.py index 9503f98a..2def6231 100755 --- a/src/gmv/gmvault_utils.py +++ b/src/gmv/gmvault_utils.py @@ -395,15 +395,17 @@ def contains_any(string, char_set): return 1 in [c in string for c in char_set] def makedirs(a_path): - """ my own version of makedir """ - - if os.path.isdir(a_path): - # it already exists so return - return - elif os.path.isfile(a_path): - raise OSError("a file with the same name as the desired dir, '%s', already exists."%(a_path)) - - os.makedirs(a_path) + """ + Create all the intermediate directories in a path. + Similar to the `mkdir -p` command. + """ + try: + os.makedirs(a_path) + except OSError as exc: # Python >2.5 + if exc.errno == errno.EEXIST and os.path.isdir(a_path): + pass + else: + raise def __rmgeneric(path, __func__): """ private function that is part of delete_all_under """ From 8ff99d9e78726561988870640a46cc4ac3f16c30 Mon Sep 17 00:00:00 2001 From: Maciek Date: Sun, 24 Feb 2019 18:00:44 +0100 Subject: [PATCH 3/3] Add missing import Fixes : "NameError: global name 'errno' is not defined" --- src/gmv/gmvault_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gmv/gmvault_utils.py b/src/gmv/gmvault_utils.py index 2def6231..cd8b476a 100755 --- a/src/gmv/gmvault_utils.py +++ b/src/gmv/gmvault_utils.py @@ -33,6 +33,7 @@ import locale import urllib import chardet +import errno import gmv.log_utils as log_utils import gmv.conf.conf_helper