[aur-dev] [PATCH] Add new chmod_group function

Dan McGee dan at archlinux.org
Fri Oct 24 17:29:03 EDT 2008


This will chmod a given directory and all its contents to the correct
group-writeable permissions.

Signed-off-by: Dan McGee <dan at archlinux.org>
---
 web/lib/aur.inc |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/web/lib/aur.inc b/web/lib/aur.inc
index d0c2bc2..3bc3637 100644
--- a/web/lib/aur.inc
+++ b/web/lib/aur.inc
@@ -390,6 +390,33 @@ function rm_rf($dirname="") {
 	return;
 }
 
+# recursive chmod to set group write permissions
+#
+function chmod_group($path) {
+	if (!is_dir($path))
+		return chmod($path, 0664);
+
+	$d = dir($path);
+	while ($f = $d->read()) {
+		if ($f != '.' && $f != '..') {
+			$fullpath = $path.'/'.$f;
+			if (is_link($fullpath))
+				continue;
+			elseif (!is_dir($fullpath))
+				if (!chmod($fullpath, 0664))
+					return FALSE;
+				elseif(!chmod_group($fullpath))
+					return FALSE;
+		}
+	}
+	$d->close();
+
+	if(chmod($path, 0775))
+		return TRUE;
+	else
+		return FALSE;
+}
+
 # obtain the uid given a Users.Username
 #
 function uid_from_username($username="")
-- 
1.6.0.3




More information about the aur-dev mailing list