@@ -42,9 +42,9 @@ def update_permissions( # noqa: C901
4242 """
4343
4444 if isinstance (base_paths , str ):
45- directories = [base_paths ]
45+ paths = [Path ( base_paths ) ]
4646 else :
47- directories = base_paths
47+ paths = [ Path ( path ) for path in base_paths ]
4848
4949 new_uid = os .getuid ()
5050 new_gid = grp .getgrnam (group ).gr_gid
@@ -67,33 +67,25 @@ def update_permissions( # noqa: C901
6767
6868 mask = stat .S_IRWXU | stat .S_IRWXG | stat .S_IRWXO
6969
70- # first the base directories that don't seem to be included in
71- # os.walk()
72- for directory in directories :
73- try :
74- dir_stat = os .stat (directory )
75- except OSError :
76- continue
77-
78- perm = dir_stat .st_mode & mask
79-
80- if (
81- perm == exec_perm
82- and dir_stat .st_uid == new_uid
83- and dir_stat .st_gid == new_gid
84- ):
85- pass
70+ for path in paths :
71+ print (f'Updating file permissions for: { path } ' )
8672
87- try :
88- os .chown (directory , new_uid , new_gid )
89- os .chmod (directory , exec_perm )
90- except OSError as e :
91- print (f'{ e } – skipping { directory } ' )
73+ # start by updating the top level path (file or directory)
74+ _update (
75+ path ,
76+ uid = new_uid ,
77+ gid = new_gid ,
78+ read_write_perm = read_write_perm ,
79+ exec_perm = exec_perm ,
80+ mask = mask ,
81+ )
9282
93- paths_iter = (p for p in Path (directory ).rglob ('*' ))
94- n_files = sum (1 for _ in Path (directory ).rglob ('*' ))
83+ # iterate over the path recursively, only if it's a direcotry
84+ if path .is_file ():
85+ continue
9586
96- print (f'Updating file permissions for: { directory } ' )
87+ paths_iter = (p for p in Path (path ).rglob ('*' ))
88+ n_files = sum (1 for _ in Path (path ).rglob ('*' ))
9789
9890 with (
9991 ThreadPoolExecutor (max_workers = workers ) as pool ,
0 commit comments