mirror of
https://github.com/Icinga/icingaweb2.git
synced 2026-05-28 04:02:39 -04:00
Add SPDX license headers and mark source files as GPL-3.0-or-later to preserve the option to relicense under later GPL versions.
61 lines
1.5 KiB
PHP
61 lines
1.5 KiB
PHP
<?php
|
|
|
|
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
namespace Icinga\File\Storage;
|
|
|
|
use ErrorException;
|
|
use RecursiveDirectoryIterator;
|
|
use RecursiveIteratorIterator;
|
|
|
|
/**
|
|
* Stores files in a temporary directory
|
|
*/
|
|
class TemporaryLocalFileStorage extends LocalFileStorage
|
|
{
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid();
|
|
mkdir($path, 0700);
|
|
|
|
parent::__construct($path);
|
|
}
|
|
|
|
/**
|
|
* Destructor
|
|
*/
|
|
public function __destruct()
|
|
{
|
|
// Some classes may have cleaned up the tmp file, so we need to check this
|
|
// beforehand to prevent an unexpected crash.
|
|
if (! @realpath($this->baseDir)) {
|
|
return;
|
|
}
|
|
|
|
$directoryIterator = new RecursiveIteratorIterator(
|
|
new RecursiveDirectoryIterator(
|
|
$this->baseDir,
|
|
RecursiveDirectoryIterator::CURRENT_AS_FILEINFO
|
|
| RecursiveDirectoryIterator::KEY_AS_PATHNAME
|
|
| RecursiveDirectoryIterator::SKIP_DOTS
|
|
),
|
|
RecursiveIteratorIterator::CHILD_FIRST
|
|
);
|
|
|
|
foreach ($directoryIterator as $path => $entry) {
|
|
/** @var \SplFileInfo $entry */
|
|
|
|
if ($entry->isDir() && ! $entry->isLink()) {
|
|
rmdir($path);
|
|
} else {
|
|
unlink($path);
|
|
}
|
|
}
|
|
|
|
rmdir($this->baseDir);
|
|
}
|
|
}
|