Skip to content
Snippets Groups Projects
Commit ea3b22b5 authored by totten's avatar totten
Browse files

CRM-14091, CRM-14092 - restrictAccess - Avoid unnecessary writes

parent a8488826
No related branches found
No related tags found
No related merge requests found
......@@ -380,11 +380,11 @@ class CRM_Utils_File {
*
* @param string $dir the directory to be secured
*/
static function restrictAccess($dir) {
static function restrictAccess($dir, $overwrite = FALSE) {
// note: empty value for $dir can play havoc, since that might result in putting '.htaccess' to root dir
// of site, causing site to stop functioning.
// FIXME: we should do more checks here -
if (!empty($dir)) {
if (!empty($dir) && is_dir($dir)) {
$htaccess = <<<HTACCESS
<Files "*">
Order allow,deny
......@@ -393,8 +393,10 @@ class CRM_Utils_File {
HTACCESS;
$file = $dir . '.htaccess';
if (file_put_contents($file, $htaccess) === FALSE) {
CRM_Core_Error::movedSiteError($file);
if ($overwrite || !file_exists($file)) {
if (file_put_contents($file, $htaccess) === FALSE) {
CRM_Core_Error::movedSiteError($file);
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment