Skip to content

Commit

Permalink
Issue #2834525 by alexpott, kim.pepper, jummonk, joshua.roberson, Ruu…
Browse files Browse the repository at this point in the history
…ds: Permission denied caused by race condition during ensureDirectory should be silenced

(cherry picked from commit 16209df49673e360579af9efcaa242c1014565ce)
  • Loading branch information
catch committed Jun 29, 2020
1 parent 2bffb90 commit 9e846da
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/Drupal/Component/FileSecurity/FileSecurity.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FileSecurity {
* TRUE if the file already exists or was created. FALSE otherwise.
*/
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);
}

/**
Expand Down Expand Up @@ -110,7 +110,7 @@ protected static function denyPublicAccess() {
* TRUE if the file already exists or was created. FALSE otherwise.
*/
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);
}

/**
Expand Down Expand Up @@ -152,7 +152,12 @@ protected static function writeFile($directory, $filename, $contents, $force) {
if (file_exists($file_path) && !$force) {
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 FALSE;
Expand Down

0 comments on commit 9e846da

Please sign in to comment.