Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
  • Loading branch information...
commit 74830b9b93a07897d017d4b564b236e72f997f88 1 parent 0785ace
@rchavik rchavik authored
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');
}
/**
@@ -117,12 +120,52 @@ function_exists('mime_content_type') && false === mime_content_type($this->File-
$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;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.