Skip to content

Commit

Permalink
Add creating of cache directory if not exists (#1302)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz authored Nov 30, 2023
1 parent 20c23c1 commit 4bb7ddc
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/Supportive/DependencyInjection/ServiceContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,21 @@ private static function loadServices(ContainerBuilder $container, ?SplFileInfo $
return;
}

if (!file_exists($cacheFile->getPathname())
&& !touch($cacheFile->getPathname())
&& !is_writable($cacheFile->getPathname())
) {
throw CacheFileException::notWritable($cacheFile);
if (!file_exists($cacheFile->getPathname())) {
$dirname = $cacheFile->getPath() ?: '.';

if (!is_dir($dirname)
&& mkdir($dirname.'/', 0777, true)
&& !is_dir($dirname)
) {
throw CacheFileException::notWritable($cacheFile);
}

if (!touch($cacheFile->getPathname())
&& !is_writable($cacheFile->getPathname())
) {
throw CacheFileException::notWritable($cacheFile);
}
}

$container->setParameter('deptrac.cache_file', $cacheFile->getPathname());
Expand Down

0 comments on commit 4bb7ddc

Please sign in to comment.