Commit 3f10ce60 authored by catch's avatar catch

Issue #2834525 by alexpott, kim.pepper, jummonk, joshua.roberson, Ruuds:...

Issue #2834525 by alexpott, kim.pepper, jummonk, joshua.roberson, Ruuds: Permission denied caused by race condition during ensureDirectory should be silenced

(cherry picked from commit 16209df4)
parent da1bddfb
...@@ -28,7 +28,7 @@ class FileSecurity { ...@@ -28,7 +28,7 @@ class FileSecurity {
* TRUE if the file already exists or was created. FALSE otherwise. * TRUE if the file already exists or was created. FALSE otherwise.
*/ */
public static function writeHtaccess($directory, $deny_public_access = TRUE, $force = FALSE) { public static function writeHtaccess($directory, $deny_public_access = TRUE, $force = FALSE) {
return self::writeFile($directory, '/.htaccess', self::htaccessLines($deny_public_access), $force); return self::writeFile($directory, '.htaccess', self::htaccessLines($deny_public_access), $force);
} }
/** /**
...@@ -112,7 +112,7 @@ protected static function denyPublicAccess() { ...@@ -112,7 +112,7 @@ protected static function denyPublicAccess() {
* TRUE if the file already exists or was created. FALSE otherwise. * TRUE if the file already exists or was created. FALSE otherwise.
*/ */
public static function writeWebConfig($directory, $force = FALSE) { public static function writeWebConfig($directory, $force = FALSE) {
return self::writeFile($directory, '/web.config', self::webConfigLines(), $force); return self::writeFile($directory, 'web.config', self::webConfigLines(), $force);
} }
/** /**
...@@ -154,7 +154,9 @@ protected static function writeFile($directory, $filename, $contents, $force) { ...@@ -154,7 +154,9 @@ protected static function writeFile($directory, $filename, $contents, $force) {
if (file_exists($file_path) && !$force) { if (file_exists($file_path) && !$force) {
return TRUE; return TRUE;
} }
if (file_exists($directory) && is_writable($directory) && file_put_contents($file_path, $contents)) { // Try to write the file. This can fail if concurrent requests are both
// trying to write a the same time.
if (@file_put_contents($file_path, $contents)) {
return @chmod($file_path, 0444); return @chmod($file_path, 0444);
} }
return FALSE; return FALSE;
......
...@@ -26,7 +26,7 @@ class FileSecurity { ...@@ -26,7 +26,7 @@ class FileSecurity {
* TRUE if the file already exists or was created. FALSE otherwise. * TRUE if the file already exists or was created. FALSE otherwise.
*/ */
public static function writeHtaccess($directory, $deny_public_access = TRUE, $force = FALSE) { public static function writeHtaccess($directory, $deny_public_access = TRUE, $force = FALSE) {
return self::writeFile($directory, '/.htaccess', self::htaccessLines($deny_public_access), $force); return self::writeFile($directory, '.htaccess', self::htaccessLines($deny_public_access), $force);
} }
/** /**
...@@ -110,7 +110,7 @@ protected static function denyPublicAccess() { ...@@ -110,7 +110,7 @@ protected static function denyPublicAccess() {
* TRUE if the file already exists or was created. FALSE otherwise. * TRUE if the file already exists or was created. FALSE otherwise.
*/ */
public static function writeWebConfig($directory, $force = FALSE) { public static function writeWebConfig($directory, $force = FALSE) {
return self::writeFile($directory, '/web.config', self::webConfigLines(), $force); return self::writeFile($directory, 'web.config', self::webConfigLines(), $force);
} }
/** /**
...@@ -152,7 +152,12 @@ protected static function writeFile($directory, $filename, $contents, $force) { ...@@ -152,7 +152,12 @@ protected static function writeFile($directory, $filename, $contents, $force) {
if (file_exists($file_path) && !$force) { if (file_exists($file_path) && !$force) {
return TRUE; return TRUE;
} }
if (file_exists($directory) && is_writable($directory) && file_put_contents($file_path, $contents)) { // Writing the file can fail if:
// - concurrent requests are both trying to write at the same time.
// - $directory does not exist or is not writable.
// Testing for these conditions introduces windows for concurrency issues to
// occur.
if (@file_put_contents($file_path, $contents)) {
return @chmod($file_path, 0444); return @chmod($file_path, 0444);
} }
return FALSE; return FALSE;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment