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.
This commit is contained in:
Rachman Chavik 2012-04-24 20:01:20 +07:00
parent 9e3fe633bb
commit 2f87992d15
2 changed files with 45 additions and 4 deletions

View file

@ -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);
}
/**

View file

@ -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;
}
}