1
1
<?php
2
2
// Directory helper functions.
3
- // (C) 2018 CubicleSoft. All Rights Reserved.
3
+ // (C) 2022 CubicleSoft. All Rights Reserved.
4
4
5
5
class DirHelper
6
6
{
@@ -68,11 +68,35 @@ public static function SetPermissions($path, $dirowner, $dirgroup, $dirperms, $f
68
68
{
69
69
$ path = rtrim (str_replace ("\\" , "/ " , $ path ), "/ " );
70
70
71
+ if (is_string ($ dirowner ))
72
+ {
73
+ $ dirowner = (function_exists ("posix_getpwnam " ) ? @posix_getpwnam ($ dirowner ) : false );
74
+ if ($ dirowner !== false ) $ dirowner = $ dirowner ["uid " ];
75
+ }
76
+
77
+ if (is_string ($ dirgroup ))
78
+ {
79
+ $ dirgroup = (function_exists ("posix_getgrnam " ) ? @posix_getgrnam ($ dirgroup ) : false );
80
+ if ($ dirgroup !== false ) $ dirgroup = $ dirgroup ["gid " ];
81
+ }
82
+
83
+ if (is_string ($ fileowner ))
84
+ {
85
+ $ fileowner = (function_exists ("posix_getpwnam " ) ? @posix_getpwnam ($ fileowner ) : false );
86
+ if ($ fileowner !== false ) $ fileowner = $ fileowner ["uid " ];
87
+ }
88
+
89
+ if (is_string ($ filegroup ))
90
+ {
91
+ $ filegroup = (function_exists ("posix_getgrnam " ) ? @posix_getgrnam ($ filegroup ) : false );
92
+ if ($ filegroup !== false ) $ filegroup = $ filegroup ["gid " ];
93
+ }
94
+
71
95
if (!isset ($ exclude [$ path ]))
72
96
{
73
- if ($ dirowner !== false ) @chown ($ path , $ dirowner );
74
- if ($ dirgroup !== false ) @chgrp ($ path , $ dirgroup );
75
- if ($ dirperms !== false ) @chmod ($ path , $ dirperms );
97
+ if ($ dirowner !== false && @ fileowner ( $ path ) !== $ dirownwer ) @chown ($ path , $ dirowner );
98
+ if ($ dirgroup !== false && @ filegroup ( $ path ) !== $ dirgroup ) @chgrp ($ path , $ dirgroup );
99
+ if ($ dirperms !== false && @ fileperms ( $ path ) & 07777 !== $ dirperms ) @chmod ($ path , $ dirperms );
76
100
}
77
101
78
102
$ dir = @opendir ($ path );
@@ -88,9 +112,9 @@ public static function SetPermissions($path, $dirowner, $dirgroup, $dirperms, $f
88
112
}
89
113
else
90
114
{
91
- if ($ fileowner !== false ) @chown ($ path . "/ " . $ file , $ fileowner );
92
- if ($ filegroup !== false ) @chgrp ($ path . "/ " . $ file , $ filegroup );
93
- if ($ fileperms !== false ) @chmod ($ path . "/ " . $ file , $ fileperms );
115
+ if ($ fileowner !== false && @ fileowner ( $ path . " / " . $ file ) !== $ fileowner ) @chown ($ path . "/ " . $ file , $ fileowner );
116
+ if ($ filegroup !== false && @ filegroup ( $ path . " / " . $ file ) !== $ filegroup ) @chgrp ($ path . "/ " . $ file , $ filegroup );
117
+ if ($ fileperms !== false && @ fileperms ( $ path . " / " . $ file ) & 07777 !== $ fileperms ) @chmod ($ path . "/ " . $ file , $ fileperms );
94
118
}
95
119
}
96
120
}
0 commit comments