[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [chutney/master] TorNet: update mkdir_p() to work with pathlib



commit a66a3cc5942fb3c103d62ea08483d459b1b6c245
Author: c <c@xxxxxxxxxxx>
Date:   Sun Jul 5 08:00:29 2020 +0000

    TorNet: update mkdir_p() to work with pathlib
    
    Modify both mkdir_p() function signature, return value, and calling
    spots to accomodate for the change from os.path to pathlib
---
 lib/chutney/TorNet.py | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/lib/chutney/TorNet.py b/lib/chutney/TorNet.py
index fb2b8a4..f33cc42 100644
--- a/lib/chutney/TorNet.py
+++ b/lib/chutney/TorNet.py
@@ -100,7 +100,7 @@ def getenv_bool(env_var, default):
         else:
             return getenv_type(env_var, default, bool, type_name='a bool')
 
-def mkdir_p(d, mode=448):
+def mkdir_p(*d, mode=448):
     """Create directory 'd' and all of its parents as needed.  Unlike
        os.makedirs, does not give an error if d already exists.
 
@@ -112,12 +112,7 @@ def mkdir_p(d, mode=448):
        permissions for the intermediate directories.  In python3, 'mode'
        only sets the mode for the last directory created.
     """
-    try:
-        os.makedirs(d, mode=mode)
-    except OSError as e:
-        if e.errno == errno.EEXIST:
-            return
-        raise
+    Path(*d).mkdir(mode=mode, parents=True, exist_ok=True)
 
 def make_datadir_subdirectory(datadir, subdir):
     """
@@ -125,7 +120,7 @@ def make_datadir_subdirectory(datadir, subdir):
        that datadirectory.  Ensure that both are mode 700.
     """
     mkdir_p(datadir)
-    mkdir_p(os.path.join(datadir, subdir))
+    mkdir_p(datadir, subdir)
 
 def get_absolute_chutney_path():
     """



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits