From 2f87992d157f2e172731a9421909db1128d69a2e Mon Sep 17 00:00:00 2001 From: Rachman Chavik Date: Tue, 24 Apr 2012 20:01:20 +0700 Subject: [PATCH] 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: f9f1c4df5 Cherrypicked from 2.2 branch. --- lib/Cake/Test/Case/Utility/FileTest.php | 47 +++++++++++++++++++++++-- lib/Cake/Utility/File.php | 2 -- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/FileTest.php b/lib/Cake/Test/Case/Utility/FileTest.php index 1f6beee0a..70b20d98a 100644 --- a/lib/Cake/Test/Case/Utility/FileTest.php +++ b/lib/Cake/Test/Case/Utility/FileTest.php @@ -53,6 +53,9 @@ class FileTest extends CakeTestCase { parent::tearDown(); $this->File->close(); unset($this->File); + + $Folder = new Folder(); + $Folder->delete(TMP . 'tests' . DS . 'permissions'); } /** @@ -116,12 +119,52 @@ class FileTest extends CakeTestCase { $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(); - $expecting = decoct(0644 & ~umask()); + $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); } /** diff --git a/lib/Cake/Utility/File.php b/lib/Cake/Utility/File.php index ed72a9008..a7914f837 100644 --- a/lib/Cake/Utility/File.php +++ b/lib/Cake/Utility/File.php @@ -110,9 +110,7 @@ class File { 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; } }