Skip to content

Commit

Permalink
File::create() does not need to change umask
Browse files Browse the repository at this point in the history
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
rchavik committed Apr 24, 2012
1 parent 9e3fe63 commit 2f87992
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
45 changes: 44 additions & 1 deletion lib/Cake/Test/Case/Utility/FileTest.php
Expand Up @@ -53,6 +53,9 @@ public function tearDown() {
parent::tearDown();
$this->File->close();
unset($this->File);

$Folder = new Folder();
$Folder->delete(TMP . 'tests' . DS . 'permissions');
}

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

/**
Expand Down
2 changes: 0 additions & 2 deletions lib/Cake/Utility/File.php
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 2f87992

Please sign in to comment.