Skip to content

Commit

Permalink
Fix permissions setting script.
Browse files Browse the repository at this point in the history
I had the permissions bits backwards the first time around. This
actually sets w+xw.
  • Loading branch information
markstory committed Sep 6, 2013
1 parent acaad33 commit d4bc47d
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions App/App/Console/Installer.php
Expand Up @@ -64,7 +64,25 @@ public static function createAppConfig($dir, $io) {
* @return void
*/
public static function setTmpPermissions($dir, $io) {
$walker = function ($dir, $perms) use ($io, &$walker) {
/**
* Change the permissions on a path and output the results.
*/
$changePerms = function ($path, $perms, $io) {
// Get current permissions in decimal format so we can bitmask it.
$currentPerms = octdec(substr(sprintf('%o', fileperms($path)), -4));
if (($currentPerms & $perms) == $perms) {
return;
}

$res = chmod($path, $currentPerms | $perms);
if ($res) {
$io->write('Permissions set on ' . $path);
} else {
$io->write('Failed to set permissions on ' . $path);
}
};

$walker = function ($dir, $perms, $io) use (&$walker, $changePerms) {
$files = array_diff(scandir($dir), ['.', '..']);
foreach ($files as $file) {
$path = $dir . '/' . $file;
Expand All @@ -73,24 +91,14 @@ public static function setTmpPermissions($dir, $io) {
continue;
}

// Get current permissions in decimal format so we can bitmask it.
$currentPerms = octdec(substr(sprintf('%o', fileperms($path)), -4));
if (($currentPerms & $perms) == $perms) {
continue;
}

$res = chmod($path, $currentPerms | $perms);
if ($res) {
$io->write('Permissions set on ' . $path);
} else {
$io->write('Failed to set permissions on ' . $path);
}
$walker($path, $perms);
$changePerms($path, $perms, $io);
$walker($path, $perms, $io);
}
};

$worldWritable = bindec('0110000000');
$walker($dir . '/tmp', $worldWritable);
$worldWritable = bindec('0000000111');
$walker($dir . '/tmp', $worldWritable, $io);
$changePerms($dir . '/tmp', $worldWritable, $io);
}

}

0 comments on commit d4bc47d

Please sign in to comment.