Permalink
Browse files

[Filesystem] Fix Filesystem::chmod to apply umask properly

  • Loading branch information...
1 parent 7ef38c1 commit a14b577c65f81d9075f828bb6e4fba0d8346cfda @Seldaek Seldaek committed Apr 19, 2012
Showing with 26 additions and 7 deletions.
  1. +2 −7 Filesystem.php
  2. +24 −0 Tests/FilesystemTest.php
View
@@ -106,19 +106,14 @@ public function remove($files)
* Change mode for an array of files or directories.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to change mode
- * @param integer $mode The new mode
+ * @param integer $mode The new mode (octal)
* @param integer $umask The mode mask (octal)
*/
public function chmod($files, $mode, $umask = 0000)
{
- $currentUmask = umask();
- umask($umask);
-
foreach ($this->toIterator($files) as $file) {
- chmod($file, $mode);
+ chmod($file, $mode ^ $umask);
}
-
- umask($currentUmask);
}
/**
@@ -315,6 +315,8 @@ public function testRemoveCleansInvalidLinks()
public function testChmodChangesFileMode()
{
+ $this->markAsSkippedIfChmodIsMissing();
+
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
touch($file);
@@ -323,8 +325,21 @@ public function testChmodChangesFileMode()
$this->assertEquals(753, $this->getFilePermisions($file));
}
+ public function testChmodAppliesUmask()
+ {
+ $this->markAsSkippedIfChmodIsMissing();
+
+ $file = $this->workspace.DIRECTORY_SEPARATOR.'file';
+ touch($file);
+
+ $this->filesystem->chmod($file, 0777, 0022);
+ $this->assertEquals(755, $this->getFilePermisions($file));
+ }
+
public function testChmodChangesModeOfArrayOfFiles()
{
+ $this->markAsSkippedIfChmodIsMissing();
+
$directory = $this->workspace.DIRECTORY_SEPARATOR.'directory';
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
$files = array($directory, $file);
@@ -340,6 +355,8 @@ public function testChmodChangesModeOfArrayOfFiles()
public function testChmodChangesModeOfTraversableFileObject()
{
+ $this->markAsSkippedIfChmodIsMissing();
+
$directory = $this->workspace.DIRECTORY_SEPARATOR.'directory';
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
$files = new \ArrayObject(array($directory, $file));
@@ -547,4 +564,11 @@ private function markAsSkippedIfSymlinkIsMissing()
$this->markTestSkipped('symlink is not supported');
}
}
+
+ private function markAsSkippedIfChmodIsMissing()
+ {
+ if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
+ $this->markTestSkipped('chmod is not supported on windows');
+ }
+ }
}

0 comments on commit a14b577

Please sign in to comment.