Added a shutdown task to finalize permissions for some directories that could be made un-writable after certain operations.

This commit is contained in:
Netkas 2022-12-22 17:32:15 -05:00
parent c0db3ac4c6
commit fa31416932
3 changed files with 40 additions and 1 deletions

View file

@ -17,6 +17,7 @@
use ncc\Exceptions\RuntimeException; use ncc\Exceptions\RuntimeException;
use ncc\ncc; use ncc\ncc;
use ncc\Utilities\Console; use ncc\Utilities\Console;
use ncc\Utilities\Functions;
use ncc\Utilities\Resolver; use ncc\Utilities\Resolver;
use ncc\Utilities\RuntimeCache; use ncc\Utilities\RuntimeCache;
@ -182,8 +183,8 @@
*/ */
public static function shutdown(): void public static function shutdown(): void
{ {
Console::outDebug('clearing cache');
RuntimeCache::clearCache(); RuntimeCache::clearCache();
Functions::finalizePermissions();
} }
} }

View file

@ -942,4 +942,40 @@
return (string)$input; return (string)$input;
} }
/**
* Finalizes the permissions
*
* @return void
* @throws InvalidScopeException
*/
public static function finalizePermissions()
{
if(Resolver::resolveScope() !== Scopes::System)
return;
Console::outVerbose('Finalizing permissions...');
$filesystem = new Filesystem();
try
{
if($filesystem->exists(PathFinder::getDataPath() . DIRECTORY_SEPARATOR . 'data'))
$filesystem->chmod(PathFinder::getDataPath() . DIRECTORY_SEPARATOR . 'data', 0777, 0000, true);
}
catch(Exception $e)
{
Console::outWarning(sprintf('Failed to finalize permissions for %s: %s', PathFinder::getDataPath() . DIRECTORY_SEPARATOR . 'data', $e->getMessage()));
}
try
{
if($filesystem->exists(PathFinder::getCachePath()))
$filesystem->chmod(PathFinder::getCachePath(), 0777, 0000, true);
}
catch(Exception $e)
{
Console::outWarning(sprintf('Failed to finalize permissions for %s: %s', PathFinder::getDataPath() . DIRECTORY_SEPARATOR . 'data', $e->getMessage()));
}
}
} }

View file

@ -86,6 +86,8 @@
*/ */
public static function clearCache(bool $clear_memory=true, bool $clear_files=true): void public static function clearCache(bool $clear_memory=true, bool $clear_files=true): void
{ {
Console::outDebug('clearing cache');
if($clear_memory) if($clear_memory)
{ {
Console::outDebug(sprintf('clearing memory cache (%d entries)', count(self::$cache))); Console::outDebug(sprintf('clearing memory cache (%d entries)', count(self::$cache)));