]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: allow passing pathlib.Path objects to file_utils.makedirs
authorJohn Mulligan <jmulligan@redhat.com>
Fri, 24 Nov 2023 19:45:01 +0000 (14:45 -0500)
committerAdam King <adking@redhat.com>
Tue, 20 Feb 2024 14:04:02 +0000 (09:04 -0500)
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 <jmulligan@redhat.com>
(cherry picked from commit 21a16007e4e578e04907775aa4e96febf02d862e)

src/cephadm/cephadmlib/file_utils.py

index 9c1ca50b925542c15442800b0623c9c9c9384f78..399729f2dccbd0da3ebf4c7825fe72d26e45195d 100644 (file)
@@ -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: