Skip to content
Browse files

File::create() does not need to change umask

umask(0) causes all files to be created with 666 permission.
After input from jrbasso and AD7six, this was found to be an
additional code to support caching using file engine.

FileEngine has since moved to SplFile since 2.x and thus umask
juggling is not required anymore.

Refs: f9f1c4d
Cherrypicked from 2.2 branch.
  • Loading branch information...
1 parent 9e3fe63 commit 2f87992d157f2e172731a9421909db1128d69a2e @rchavik rchavik committed
Showing with 44 additions and 3 deletions.
  1. +44 −1 lib/Cake/Test/Case/Utility/FileTest.php
  2. +0 −2 lib/Cake/Utility/File.php
View
45 lib/Cake/Test/Case/Utility/FileTest.php
@@ -53,6 +53,9 @@ public function tearDown() {
parent::tearDown();
$this->File->close();
unset($this->File);
+
+ $Folder = new Folder();
+ $Folder->delete(TMP . 'tests' . DS . 'permissions');
}
/**
@@ -116,12 +119,52 @@ public function testBasic() {
$result = $this->File->Folder();
$this->assertInstanceOf('Folder', $result);
+ }
+/**
+ * testPermission method
+ */
+ public function testPermission() {
$this->skipIf(DIRECTORY_SEPARATOR === '\\', 'File permissions tests not supported on Windows.');
- $result = $this->File->perms();
+ $dir = TMP . 'tests' . DS . 'permissions' . DS;
+ $Folder = new Folder($dir);
+
+ $old = umask();
+
+ umask(0002);
+ $file = $dir . 'permission_' . uniqid();
+ $expecting = decoct(0664 & ~umask());
+ $File = new File($file, true);
+ $result = $File->perms();
+ $this->assertEquals($expecting, $result);
+ $File->delete();
+
+ umask(0022);
+ $file = $dir . 'permission_' . uniqid();
$expecting = decoct(0644 & ~umask());
+ $File = new File($file, true);
+ $result = $File->perms();
+ $this->assertEquals($expecting, $result);
+ $File->delete();
+
+ umask(0422);
+ $file = $dir . 'permission_' . uniqid();
+ $expecting = decoct(0244 & ~umask());
+ $File = new File($file, true);
+ $result = $File->perms();
$this->assertEquals($expecting, $result);
+ $File->delete();
+
+ umask(0444);
+ $file = $dir . 'permission_' . uniqid();
+ $expecting = decoct(0222 & ~umask());
+ $File = new File($file, true);
+ $result = $File->perms();
+ $this->assertEquals($expecting, $result);
+ $File->delete();
+
+ umask($old);
}
/**
View
2 lib/Cake/Utility/File.php
@@ -110,9 +110,7 @@ public function __destruct() {
public function create() {
$dir = $this->Folder->pwd();
if (is_dir($dir) && is_writable($dir) && !$this->exists()) {
- $old = umask(0);
if (touch($this->path)) {
- umask($old);
return true;
}
}

0 comments on commit 2f87992

Please sign in to comment.
Something went wrong with that request. Please try again.