Beispiel #1
0
 /**
  * Retrieves the container folder and optionally creates a new folder if required.
  * @param Directory The base path to use
  * @param string The name of the container. Uses the first CONTAINER_NAME_USAGE_LENGTH characters of the string. If the string is smaller, Its get zero-padded.
  * @param bool True to create the folder if it does not exists, false otherwise.
  * @return Directory Returns the requested path with the container components
  */
 protected static function getContainerFolder(\System\IO\Directory $baseFolder, $container, $createIfNotExists)
 {
     $containerNameUsage = self::getContainerNameParts($container);
     $containerNameParts = str_split($containerNameUsage);
     $containerPath = implode(\System\IO\Directory::getSeparator(), $containerNameParts);
     $basePath = new \System\IO\Directory($baseFolder->getCurrentPath() . $containerPath, false);
     if (!$basePath->exists() && $createIfNotExists) {
         $oldMask = umask(0);
         mkdir($basePath->getCurrentPath(), \System\IO\Directory::FULL_ACCESS, true);
         umask($oldMask);
     }
     if (!$basePath->exists()) {
         throw new \System\Error\Exception\FileNotFoundException('Could not create the given folder: ' . $basePath->getCurrentPath());
     }
     return $basePath;
 }
Beispiel #2
0
 /**
  * Clears out a directory recursivly.
  * Removes folders and files.
  * @return bool Returns true on success, false otherwise
  */
 public final function clear()
 {
     if ($this->exists()) {
         $contents = scandir($this->path);
         foreach ($contents as $content) {
             if ($content != '.' && $content != '..') {
                 $fullContentEntry = $this->path . self::getSeparator() . $content;
                 switch (filetype($fullContentEntry)) {
                     case FileType::FILETYPE_DIR:
                         $folder = new \System\IO\Directory($fullContentEntry);
                         $folder->clear();
                         break;
                     case FileType::FILETYPE_LINK:
                     case FileType::FILETYPE_FILE:
                         unlink($fullContentEntry);
                         break;
                     default:
                         throw new \System\Error\Exception\FileNotFoundException($fullContentEntry . ' is not recognized as a file or a folder');
                 }
             }
         }
         return rmdir($this->path);
     }
     return false;
 }
Beispiel #3
0
 /**
  * Cleans the current file cache by deleting unused files.
  * @param \System\Db\Database The database to LUT query
  */
 public static final function cleanPageCache(\System\Db\Database $db)
 {
     $results = \System\Cache\LUTCache\LUTCache::getCache($db);
     $baseFiles = new \System\Collection\Vector();
     foreach ($results as $result) {
         $baseFiles[] = basename($result->value);
     }
     $folder = new \System\IO\Directory(\System\Cache\PageCache\StaticBlock::CACHE_CACHEFOLDER);
     $extensions = new \System\Collection\Vector('xml');
     $files = $folder->getFiles($extensions);
     foreach ($files as $file) {
         /** @var \System\IO\File */
         $file = $file;
         if (mb_strpos($file->getFilename(), 'PageCache') !== false) {
             if (!$baseFiles->contains($file->getFilename())) {
                 $file->delete();
             }
         }
     }
 }
Beispiel #4
0
 private static final function copyFiles(\System\IO\Directory $targetFolder, $sourceFolder, \System\Collection\Vector $fileMask, $baseSubfolder)
 {
     $files = \System\IO\Directory::walkDir($sourceFolder, $fileMask);
     $target = new \System\IO\Directory($targetFolder->getCurrentPath() . \System\IO\Directory::getSeparator() . $baseSubfolder);
     foreach ($files as $file) {
         $baseFile = $file->stripBase($sourceFolder);
         $folderParts = preg_split('/\\\\/', $baseFile);
         array_pop($folderParts);
         $newPath = $target->getCurrentPath();
         foreach ($folderParts as $part) {
             $newPath = \System\IO\Directory::getPath($newPath . \System\IO\Directory::getSeparator() . $part);
             if (!file_exists($newPath)) {
                 mkdir($newPath, 0777, true);
             }
         }
         $newPath .= \System\IO\Directory::getSeparator() . $file->getFilename();
         $file->copyFile($newPath);
     }
 }