Added a shutdown task to finalize permissions for some directories that could be made un-writable after certain operations.
This commit is contained in:
parent
c0db3ac4c6
commit
fa31416932
3 changed files with 40 additions and 1 deletions
|
@ -17,6 +17,7 @@
|
|||
use ncc\Exceptions\RuntimeException;
|
||||
use ncc\ncc;
|
||||
use ncc\Utilities\Console;
|
||||
use ncc\Utilities\Functions;
|
||||
use ncc\Utilities\Resolver;
|
||||
use ncc\Utilities\RuntimeCache;
|
||||
|
||||
|
@ -182,8 +183,8 @@
|
|||
*/
|
||||
public static function shutdown(): void
|
||||
{
|
||||
Console::outDebug('clearing cache');
|
||||
RuntimeCache::clearCache();
|
||||
Functions::finalizePermissions();
|
||||
}
|
||||
|
||||
}
|
|
@ -942,4 +942,40 @@
|
|||
|
||||
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()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -86,6 +86,8 @@
|
|||
*/
|
||||
public static function clearCache(bool $clear_memory=true, bool $clear_files=true): void
|
||||
{
|
||||
Console::outDebug('clearing cache');
|
||||
|
||||
if($clear_memory)
|
||||
{
|
||||
Console::outDebug(sprintf('clearing memory cache (%d entries)', count(self::$cache)));
|
||||
|
|
Loading…
Add table
Reference in a new issue