This commit is contained in:
the-djmaze 2024-07-11 00:25:26 +02:00
parent 57d1021d51
commit 95436347e5
8 changed files with 22 additions and 20 deletions

View file

@ -722,4 +722,19 @@ abstract class Utils
$aParts[] = $sDomain;
return \implode('@', $aParts);
}
public static function mkdir(string $directory) : void
{
if (!\is_dir($directory)) {
if (!\mkdir($directory, 0700, true)) {
throw new \RuntimeException("Failed to create directory {$directory}");
}
\clearstatcache();
}
/*
if (!\is_writable($directory)) {
throw new \Exception("Failed to access directory {$directory}");
}
*/
}
}

View file

@ -25,6 +25,7 @@ class File implements \MailSo\Cache\DriverInterface
function __construct(string $sCacheFolder)
{
$this->sCacheFolder = \rtrim(\trim($sCacheFolder), '\\/').'/';
\MailSo\Base\Utils::mkdir($this->sCacheFolder);
// http://www.brynosaurus.com/cachedir/
$tag = $this->sCacheFolder . 'CACHEDIR.TAG';

View file

@ -59,9 +59,7 @@ trait Pgp
\RainLoop\Providers\Storage\Enumerations\StorageType::ROOT
), '/') . '/.gnupg';
if (!\is_dir($homedir)) {
\mkdir($homedir, 0700, true);
}
\MailSo\Base\Utils::mkdir($homedir);
if (!\is_writable($homedir)) {
throw new \Exception("gpg homedir '{$homedir}' not writable");
}

View file

@ -22,9 +22,7 @@ trait SMime
\RainLoop\Providers\Storage\Enumerations\StorageType::ROOT
), '/') . '/.smime';
if (!\is_dir($homedir)) {
\mkdir($homedir, 0700, true);
}
\MailSo\Base\Utils::mkdir($homedir);
if (!\is_writable($homedir)) {
throw new \Exception("smime homedir '{$homedir}' not writable");
}

View file

@ -147,9 +147,7 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
.($sSubEmail ? '/'.\MailSo\Base\Utils::SecureFileName($sSubEmail) : '')
.'/.files/'.\sha1($sKey);
if ($bMkDir && !\is_dir(\dirname($sFilePath)) && !\mkdir(\dirname($sFilePath), 0700, true)) {
throw new \RuntimeException('Can\'t make storage directory "'.$sFilePath.'"');
}
$bMkDir && \MailSo\Base\Utils::mkdir(\dirname($sFilePath));
return $sFilePath;
}

View file

@ -143,10 +143,7 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
}
}
if ($bMkDir && !empty($sFilePath) && !\is_dir($sFilePath) && !\mkdir($sFilePath, 0700, true))
{
throw new \RuntimeException('Can\'t make storage directory "'.$sFilePath.'"');
}
$bMkDir && !empty($sFilePath) && \MailSo\Base\Utils::mkdir($sFilePath);
return $sFilePath;
}

View file

@ -10,13 +10,7 @@ class Temporary
{
$tmpdir = \sys_get_temp_dir() . '/snappymail';
// if (\RainLoop\Utils::inOpenBasedir($tmpdir) &&
\is_dir($tmpdir) || \mkdir($tmpdir, 0700);
if (!\is_dir($tmpdir)) {
throw new \Exception("Failed to create directory {$tmpdir}");
}
if (!\is_writable($tmpdir)) {
// throw new \Exception("Failed to access directory {$tmpdir}");
}
\MailSo\Base\Utils::mkdir($tmpdir);
if ($prefix) {
$this->filename = @\tempnam($tmpdir, $name);
} else {

View file

@ -17,6 +17,7 @@ abstract class Upgrade
$sNewDir = $sDataPath
.'/'.\MailSo\Base\Utils::SecureFileName($sDomain ?: 'unknown.tld')
.'/'.\MailSo\Base\Utils::SecureFileName(\implode('@', $aEmail) ?: '.unknown');
// \MailSo\Base\Utils::mkdir($sNewDir)
if (\is_dir($sNewDir) || \mkdir($sNewDir, 0700, true)) {
foreach (\glob("{$sDomainDir}/*") as $sItem) {
$sName = \basename($sItem);