N°5235 - Add non blocking setup check : is tmp dir is writable (#301)

This commit is contained in:
Pierre Goiffon
2022-09-13 18:20:35 +02:00
committed by GitHub
parent 4c1df9927d
commit 5cf391c3bb

View File

@@ -81,16 +81,23 @@ class SetupUtils
$aResult = array();
// For log file(s)
if (!is_dir(APPROOT.'log'))
{
if (!is_dir(APPROOT.'log')) {
@mkdir(APPROOT.'log');
}
self::CheckPhpVersion($aResult);
// Check the common directories
$aWritableDirsErrors = self::CheckWritableDirs(array('log', 'env-production', 'env-production-build', 'conf', 'data'));
$aResult = array_merge($aResult, $aWritableDirsErrors);
$aWritableApprootDirsErrors = self::CheckWritableDirs(array('log', 'env-production', 'env-production-build', 'conf', 'data'));
$aResult = array_merge($aResult, $aWritableApprootDirsErrors);
// Check temp dir (N°5235) : as this path isn't under APPROOT we are doing a custom check and not using \SetupUtils::CheckWritableDirs
$sTmpDir = static::GetTmpDir();
clearstatcache(true, $sTmpDir);
if (is_writable($sTmpDir)) {
$aResult[] = new CheckResult(CheckResult::INFO, "The temp directory is writable by the application.");
} else {
$aResult[] = new CheckResult(CheckResult::ERROR, "The temp directory <b>'".$sTmpDir."'</b> is not writable by the application. Change its permission or use another dir (sys_temp_dir option in php.ini).");
}
$aMandatoryExtensions = array(
'mysqli',
@@ -1798,21 +1805,30 @@ JS
public static function GetVersionManifest($sInstalledVersion)
{
if (preg_match('/^([0-9]+)\./', $sInstalledVersion, $aMatches))
{
if (preg_match('/^([0-9]+)\./', $sInstalledVersion, $aMatches)) {
return APPROOT.'datamodels/'.$aMatches[1].'.x/manifest-'.$sInstalledVersion.'.xml';
}
return false;
}
/**
* Check paths relative to APPROOT : is existing, is dir, is writable
*
* @param string[] $aWritableDirs list of dirs to check, relative to APPROOT (for example : `['log','conf','data']`)
*
* @return array<string, \CheckResult> full path as key, CheckResult error as value
*
* @uses \is_dir()
* @uses \is_writable()
* @uses \file_exists()
*/
public static function CheckWritableDirs($aWritableDirs)
{
$aNonWritableDirs = array();
foreach($aWritableDirs as $sDir)
{
foreach ($aWritableDirs as $sDir) {
$sFullPath = APPROOT.$sDir;
if (is_dir($sFullPath) && !is_writable($sFullPath))
{
if (is_dir($sFullPath) && !is_writable($sFullPath)) {
$aNonWritableDirs[APPROOT.$sDir] = new CheckResult(CheckResult::ERROR, "The directory <b>'".APPROOT.$sDir."'</b> exists but is not writable for the application.");
}
else if (file_exists($sFullPath) && !is_dir($sFullPath))