Collects garbage - removes files from the file system.

@return \Zend\Stdlib\ResponseInterface
301
public function collectAction()
    {
        // @todo json
        $service = $this->getGarbageCollector();
        if ($service->collect()) {
            return $this->redirect()->toRoute('sc-admin/content-manager');
        }
        return $this->redirect()
            ->toRoute(
                'sc-admin/file/delete',
                ['random' => Stdlib::randomKey(6)]
            )
            ->setStatusCode(303);
    }
1336497
public function diskUsage()
    {
        if (is_dir($this->path)) {
            $diskUsage = 0;
            $iterator = new \RecursiveIteratorIterator(
                new \RecursiveDirectoryIterator(
                    $this->path,
                    \RecursiveDirectoryIterator::SKIP_DOTS
                )
            );

            foreach ($iterator as $file) {
                $diskUsage += $file->getSize();
            }
            return $diskUsage;
        }

        return filesize($this->path);
    }
989814
protected function garbageCollect()
	{
		$lifetime = $this->gc_lifetime*60*60;
		$Finder = new \RecursiveDirectoryIterator(dirname($this->dirname),
		      \FilesystemIterator::KEY_AS_FILENAME 
			| \FilesystemIterator::CURRENT_AS_FILEINFO
			| \FilesystemIterator::SKIP_DOTS);
		$now = time();
		/** @var \SplFileInfo $value */
		foreach ( $Finder as $key => $value ) {
			if ( pathinfo($key,PATHINFO_EXTENSION)=='json' && ( $value->getMtime() + $lifetime < $now) ) {
				@unlink($value->getRealPath());
			} elseif($value->isDir() && ( $value->getMtime() + $lifetime < $now)  ){
			    $path = $value->getRealPath();
			    $dir = dir($path);
			    while($f=$dir->read()){
			        if(!in_array($f,['.','..']) && is_file($path.'/'.$f)){
                        @unlink($path.'/'.$f);
                    }
                }
                $dir->close();
                @rmdir($value->getRealPath());
            }
		}
	}
192958
protected function garbageCollect()
    {
        foreach (Finder::create()->files()->name('*.json')->date('< ' . $this->gc_lifetime . ' hour ago')->in(
            $this->dirname
        ) as $file) {
            $this->files->delete($file->getRealPath());
        }
    }
852334
public function destroy()
    {
        unset($this->storage);

        $_SESSION = [];
        session_destroy();
        $this->startSession();

        $this->storage = & $_SESSION;

        return $this;
    }
1096316
public function delete() {
		if($r = \Asgard\File\FileSystem::delete($this->src)) {
			$this->src = null;
			$this->name = null;
		}
		return $r;
	}
959879
protected function handleDelete() : HttpResponse
    {
        $key      = $this->request->key();
        $fileMeta = $this->cache->get($key);
        $resource = $fileMeta['file_path'] ?? null;

        if ( ! $resource) {
            return $this->response->send(null, HttpResponse::HTTP_NOT_FOUND);
        }

        $isDeleted = $this->cache->delete($key);

        if ( ! $isDeleted || ! file_exists($resource)) {
            return $this->response->send(null, HttpResponse::HTTP_GONE);
        }

        unlink($resource);

        return $this->response->send(null, HttpResponse::HTTP_NO_CONTENT, [
            'Tus-Extension' => self::TUS_EXTENSION_TERMINATION,
        ]);
    }
676025
protected function getFilesToDelete()
    {
        $dirName    = dirname($this->baseFilename);
        $baseName   = basename($this->baseFilename);
        $fileNames  = scandir($dirName);
        $result     = array();
        $prefix     = $baseName . '.';
        $plen       = strlen($prefix);

        foreach ($fileNames as $fileName) {
            if ($fileName == '.' || $fileName == '..') {
                continue;
            }

            if (!strncmp($fileName, $prefix, $plen)) {
                $suffix = substr($fileName, $plen);
                if (preg_match($this->extMatch, $suffix)) {
                    $result[] = $dirName . DIRECTORY_SEPARATOR . $fileName;
                }
            }
        }

        sort($result);
        $rlen = count($result);
        if ($rlen < $this->backupCount) {
            $result = array();
        } else {
            $result = array_slice($result, 0, $rlen - $this->backupCount);
        }
        return $result;
    }
128510
public function destroy()
    {
        if ($this->resource) {
            imagedestroy($this->resource);
        }

        $this->resource = null;

        return $this;
    }
535608
protected function handleDELETE()
    {
        $force = $this->request->getParameterAsBool('force', false);
        $noCheck = $this->request->getParameterAsBool('no_check', false);
        $contentOnly = $this->request->getParameterAsBool('content_only', false);

        if (empty($this->folderPath)) {
            // delete just folders and files from the container
            if (!empty($content = ResourcesWrapper::unwrapResources($this->request->getPayloadData()))) {
                $result = $this->deleteFolderContent($content, '', $force);
            } else {
                throw new BadRequestException('No resources given for delete.');
            }
        } else {
            if (empty($this->filePath)) {
                // delete directory of files and the directory itself
                // multi-file or folder delete via post data
                if (!empty($content = ResourcesWrapper::unwrapResources($this->request->getPayloadData()))) {
                    $result = $this->deleteFolderContent($content, $this->folderPath, $force);
                } else {
                    $this->driver->deleteFolder($this->container, $this->folderPath, $force, $contentOnly);
                    $result = ['name' => basename($this->folderPath), 'path' => $this->folderPath];
                }
            } else {
                // delete file from permanent storage
                $this->driver->deleteFile($this->container, $this->filePath, $noCheck);
                $result = ['name' => basename($this->filePath), 'path' => $this->filePath];
            }
        }

        return ResponseFactory::create(ResourcesWrapper::cleanResources($result));
    }
263079
public function delete()
    {
        $this->triggerEvent('onBeforeDelete');

        $this->getFlexDirectory()->getStorage()->deleteRows([$this->getStorageKey() => $this->prepareStorage()]);

        try {
            $this->getFlexDirectory()->clearCache();
            if (method_exists($this, 'clearMediaCache')) {
                $this->clearMediaCache();
            }
        } catch (InvalidArgumentException $e) {
            /** @var Debugger $debugger */
            $debugger = Grav::instance()['debugger'];
            $debugger->addException($e);

            // Caching failed, but we can ignore that for now.
        }

        $this->triggerEvent('onAfterDelete');

        return $this;
    }
1134356
private function garbageCollect()
    {
        $this->setDefaultValueBinder();

        // Force garbage collecting
        unset($this->sheetImports, $this->spreadsheet);

        $this->currentFile->delete();
    }
353905
public function destroyAll()
    {
        $cacheDir = $this->getDirectory();

        if (file_exists($cacheDir)) {
            $cacheFile = fopen($cacheDir, 'w');
            fclose($cacheFile);
        }

        return $this;
    }
293132
protected function garbage_collection() {
        if (empty($this->session)) {
            return true;
        }
        foreach ($this->session as $key=>$cachedinfo) {
            if (is_array($cachedinfo) && $cachedinfo[self::CACHETIME]<$this->timeout) {
                unset($this->session[$key]);
            }
        }
    }
549592
public function getTrashService()
    {
        if ($this->trashService !== null) {
            return $this->trashService;
        }

        $this->trashService = new TrashService(
            $this,
            $this->persistenceHandler,
            $this->getNameSchemaService(),
            $this->getPermissionCriterionResolver(),
            $this->serviceSettings['trash']
        );

        return $this->trashService;
    }
664862
public function getFileSystem()
    {
        if (null == $this->fileSystem) {
            $this->setFileSystem(Helper::getFileSystem());
        }

        return $this->fileSystem;
    }
1107597
public function collectGarbage()
    {
        if ($this->freeze) {
            throw new \Exception('Backend is frozen!', 123789);
        }

        $lifetimeFiles = \glob(GeneralUtility::getFileAbsFileName(self::RELATIVE_STORAGE_FOLDER) . '*/*/*' . self::FILE_EXTENSION_LIFETIME);

        $identifiers = [];

        foreach ($lifetimeFiles as $lifetimeFile) {
            if ((int)\file_get_contents($lifetimeFile) < \time()) {
                $identifiers[] = \file_get_contents(\str_replace(self::FILE_EXTENSION_LIFETIME, self::FILE_EXTENSION_IDENTIFIER, $lifetimeFile));
            }
        }

        foreach ($identifiers as $identifier) {
            $this->remove($identifier);
        }
    }