Skip to content

Commit

Permalink
Merge pull request #11677 from mlocati/mkdir-permissions
Browse files Browse the repository at this point in the history
Fix permissions when creating directories
  • Loading branch information
aembler committed Oct 5, 2023
2 parents df0bc93 + 707b974 commit 2bba91d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
15 changes: 7 additions & 8 deletions concrete/src/Asset/CssAsset.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace Concrete\Core\Asset;

use Concrete\Core\Config\Repository\Repository;
use Concrete\Core\Html\Object\HeadLink;
use Config;

class CssAsset extends Asset
{
Expand Down Expand Up @@ -73,16 +73,15 @@ protected static function getRelativeOutputDirectory()
*/
protected static function getOutputDirectory()
{
if (!file_exists(Config::get('concrete.cache.directory').'/'.DIRNAME_CSS)) {
$proceed = @mkdir(Config::get('concrete.cache.directory').'/'.DIRNAME_CSS);
$config = app(Repository::class);
$path = $config->get('concrete.cache.directory') . '/' . DIRNAME_CSS;
if (!file_exists($path)) {
$proceed = @mkdir($path, $config->get('concrete.filesystem.permissions.directory'));
} else {
$proceed = true;
}
if ($proceed) {
return Config::get('concrete.cache.directory').'/'.DIRNAME_CSS;
} else {
return false;
}

return $proceed ? $path : false;
}

/**
Expand Down
16 changes: 8 additions & 8 deletions concrete/src/Asset/JavascriptAsset.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php
namespace Concrete\Core\Asset;

use Concrete\Core\Config\Repository\Repository;
use HtmlObject\Element;
use Config;


class JavascriptAsset extends Asset
{
Expand Down Expand Up @@ -38,16 +39,15 @@ public static function getRelativeOutputDirectory()
*/
protected static function getOutputDirectory()
{
if (!file_exists(Config::get('concrete.cache.directory').'/'.DIRNAME_JAVASCRIPT)) {
$proceed = @mkdir(Config::get('concrete.cache.directory').'/'.DIRNAME_JAVASCRIPT);
$config = app(Repository::class);
$path = $config->get('concrete.cache.directory') . '/' . DIRNAME_JAVASCRIPT;
if (!file_exists($path)) {
$proceed = @mkdir($path, $config->get('concrete.filesystem.permissions.directory'));
} else {
$proceed = true;
}
if ($proceed) {
return Config::get('concrete.cache.directory').'/'.DIRNAME_JAVASCRIPT;
} else {
return false;
}

return $proceed ? $path : false;
}

/**
Expand Down
9 changes: 6 additions & 3 deletions concrete/src/Cache/Page/FilePageCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Concrete\Core\Cache\Page;

use Config;
use Concrete\Core\Config\Repository\Repository;
use Concrete\Core\Page\Page as ConcretePage;
use Loader;

Expand Down Expand Up @@ -59,9 +60,11 @@ public function purge(ConcretePage $c)

public function set(ConcretePage $c, $content)
{
if (!is_dir(Config::get('concrete.cache.page.directory'))) {
@mkdir(Config::get('concrete.cache.page.directory'));
@touch(Config::get('concrete.cache.page.directory') . '/index.html');
$config = app(Repository::class);
$dir = $config->get('concrete.cache.page.directory');
if (!is_dir($dir)) {
@mkdir($dir, $config->get('concrete.filesystem.permissions.directory'));
@touch($dir . '/index.html');
}
$url = $c->getSite()->getSiteCanonicalURL();
$lifetime = $c->getCollectionFullPageCachingLifetimeValue();
Expand Down
2 changes: 1 addition & 1 deletion concrete/src/Console/Command/ResetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
foreach ($createEmptyDirs as $shownName => $fullpath) {
if (!file_exists($fullpath)) {
$output->write("Creating directory $shownName... ");
if (@mkdir($fullpath) === false) {
if (@mkdir($fullpath, DIRECTORY_PERMISSIONS_MODE_COMPUTED) === false) {
throw new Exception("Failed to create directory $fullpath");
}
$output->writeln('<info>done.</info>');
Expand Down
6 changes: 4 additions & 2 deletions concrete/src/Console/Command/TranslatePackageCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Concrete\Core\Console\Command;

use Concrete\Core\Config\Repository\Repository;
use Concrete\Core\Console\Command;
use Concrete\Core\Localization\Localization;
use Concrete\Core\Localization\Translation\Remote\ProviderInterface as RemoteTranslationProvider;
Expand Down Expand Up @@ -65,6 +66,7 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->app = Application::getFacadeApplication();
$config = $this->app->make(Repository::class);

$vsh = $this->app->make('helper/validation/strings');
/* @var \Concrete\Core\Utility\Service\Validation\Strings $vsh */
Expand Down Expand Up @@ -163,7 +165,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
// Save the pot file
$output->write('Saving .pot file... ');
if (!is_dir($packageLanguagesDirectory)) {
@mkdir($packageLanguagesDirectory, 0775, true);
@mkdir($packageLanguagesDirectory, $config->get('concrete.filesystem.permissions.directory'), true);
if (!is_dir($packageLanguagesDirectory)) {
throw new Exception("Unable to create the directory $packageLanguagesDirectory");
}
Expand Down Expand Up @@ -207,7 +209,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
$output->write('- saving .po file... ');
if (!is_dir($poDirectory)) {
@mkdir($poDirectory, 0775, true);
@mkdir($poDirectory, $config->get('concrete.filesystem.permissions.directory'), true);
if (!is_dir($poDirectory)) {
throw new Exception("Unable to create the directory $poDirectory");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Concrete\Core\Session\Storage\Handler;

use Concrete\Core\Config\Repository\Repository;
use SessionHandler;

/**
Expand Down Expand Up @@ -48,7 +49,7 @@ public function __construct($savePath = null)

try {
if ($baseDir && !is_dir($baseDir)) {
mkdir($baseDir, 0777, true);
mkdir($baseDir, app(Repository::class)->get('concrete.filesystem.permissions.directory'), true);
}

ini_set('session.save_path', $savePath);
Expand Down

0 comments on commit 2bba91d

Please sign in to comment.