From: John Mulligan Date: Fri, 24 Nov 2023 19:45:01 +0000 (-0500) Subject: cephadm: allow passing pathlib.Path objects to file_utils.makedirs X-Git-Tag: v19.1.0~139^2~3 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=d81091c2e9fa9670565df16d45eaf844c330b249;p=ceph.git 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) --- 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: