From d81091c2e9fa9670565df16d45eaf844c330b249 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Fri, 24 Nov 2023 14:45:01 -0500 Subject: [PATCH] cephadm: allow passing pathlib.Path objects to file_utils.makedirs Update the type annotations to allow passing pathlib.Path objects to the makedirs function. All the calls makedirs uses already can accept Path objects. This causes mypy to accept calling makedirs with a Path argument and Paths are nice. Signed-off-by: John Mulligan (cherry picked from commit 21a16007e4e578e04907775aa4e96febf02d862e) (cherry picked from commit 512154fa8d8fb58aefe5ddcedad865ad37a1634a) --- src/cephadm/cephadmlib/file_utils.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/cephadm/cephadmlib/file_utils.py b/src/cephadm/cephadmlib/file_utils.py index 9c1ca50b92554..399729f2dccbd 100644 --- a/src/cephadm/cephadmlib/file_utils.py +++ b/src/cephadm/cephadmlib/file_utils.py @@ -81,14 +81,13 @@ def write_tmp(s, uid, gid): return tmp_f -def makedirs(dir, uid, gid, mode): - # type: (str, int, int, int) -> None - if not os.path.exists(dir): - os.makedirs(dir, mode=mode) +def makedirs(dest: Union[Path, str], uid: int, gid: int, mode: int) -> None: + if not os.path.exists(dest): + os.makedirs(dest, mode=mode) else: - os.chmod(dir, mode) - os.chown(dir, uid, gid) - os.chmod(dir, mode) # the above is masked by umask... + os.chmod(dest, mode) + os.chown(dest, uid, gid) + os.chmod(dest, mode) # the above is masked by umask... def recursive_chown(path: str, uid: int, gid: int) -> None: -- 2.39.5