Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-10-22 19:36:52 +0400
committerRobin Appelman <icewind@owncloud.com>2015-01-08 18:22:44 +0300
commit3adb47094e57a81ad0af48210ea5a5e6d08b96d3 (patch)
tree4acefdff5ed097ed9037bf970841d72dc029c95b /lib
parent299ff5a3b121bff8f4c72c5f0b1eb4e0831aed10 (diff)
Use the TempManager to handle temporary files
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php3
-rw-r--r--lib/private/helper.php91
2 files changed, 6 insertions, 88 deletions
diff --git a/lib/base.php b/lib/base.php
index 5d7408e65da..701cb22afe5 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -585,7 +585,8 @@ class OC {
self::registerLogRotate();
//make sure temporary files are cleaned up
- register_shutdown_function(array('OC_Helper', 'cleanTmp'));
+ $tmpManager = \OC::$server->getTempManager();
+ register_shutdown_function(array($tmpManager, 'clean'));
//parse the given parameters
self::$REQUESTEDAPP = (isset($_GET['app']) && trim($_GET['app']) != '' && !is_null($_GET['app']) ? OC_App::cleanAppId(strip_tags($_GET['app'])) : OC_Config::getValue('defaultapp', 'files'));
diff --git a/lib/private/helper.php b/lib/private/helper.php
index cca9d29b4b1..318aaffc067 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -25,7 +25,6 @@
* Collection of useful functions
*/
class OC_Helper {
- private static $tmpFiles = array();
private static $mimetypeIcons = array();
private static $mimetypeDetector;
private static $templateManager;
@@ -548,106 +547,24 @@ class OC_Helper {
*
* @param string $postfix
* @return string
+ * @deprecated Use the TempManager instead
*
* temporary files are automatically cleaned up after the script is finished
*/
public static function tmpFile($postfix = '') {
- $file = get_temp_dir() . '/' . md5(time() . rand()) . $postfix;
- $fh = fopen($file, 'w');
- fclose($fh);
- self::$tmpFiles[] = $file;
- return $file;
- }
-
- /**
- * move a file to oc-noclean temp dir
- *
- * @param string $filename
- * @return mixed
- *
- */
- public static function moveToNoClean($filename = '') {
- if ($filename == '') {
- return false;
- }
- $tmpDirNoClean = get_temp_dir() . '/oc-noclean/';
- if (!file_exists($tmpDirNoClean) || !is_dir($tmpDirNoClean)) {
- if (file_exists($tmpDirNoClean)) {
- unlink($tmpDirNoClean);
- }
- mkdir($tmpDirNoClean);
- }
- $newname = $tmpDirNoClean . basename($filename);
- if (rename($filename, $newname)) {
- return $newname;
- } else {
- return false;
- }
+ return \OC::$server->getTempManager()->getTemporaryFile($postfix);
}
/**
* create a temporary folder with an unique filename
*
* @return string
+ * @deprecated Use the TempManager instead
*
* temporary files are automatically cleaned up after the script is finished
*/
public static function tmpFolder() {
- $path = get_temp_dir() . '/' . md5(time() . rand());
- mkdir($path);
- self::$tmpFiles[] = $path;
- return $path . '/';
- }
-
- /**
- * remove all files created by self::tmpFile
- */
- public static function cleanTmp() {
- $leftoversFile = get_temp_dir() . '/oc-not-deleted';
- if (file_exists($leftoversFile)) {
- $leftovers = file($leftoversFile);
- foreach ($leftovers as $file) {
- self::rmdirr($file);
- }
- unlink($leftoversFile);
- }
-
- foreach (self::$tmpFiles as $file) {
- if (file_exists($file)) {
- if (!self::rmdirr($file)) {
- file_put_contents($leftoversFile, $file . "\n", FILE_APPEND);
- }
- }
- }
- }
-
- /**
- * remove all files in PHP /oc-noclean temp dir
- */
- public static function cleanTmpNoClean() {
- $tmpDirNoCleanName=get_temp_dir() . '/oc-noclean/';
- if(file_exists($tmpDirNoCleanName) && is_dir($tmpDirNoCleanName)) {
- $files=scandir($tmpDirNoCleanName);
- foreach($files as $file) {
- $fileName = $tmpDirNoCleanName . $file;
- if (!\OC\Files\Filesystem::isIgnoredDir($file) && filemtime($fileName) + 600 < time()) {
- unlink($fileName);
- }
- }
- // if oc-noclean is empty delete it
- $isTmpDirNoCleanEmpty = true;
- $tmpDirNoClean = opendir($tmpDirNoCleanName);
- if(is_resource($tmpDirNoClean)) {
- while (false !== ($file = readdir($tmpDirNoClean))) {
- if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
- $isTmpDirNoCleanEmpty = false;
- }
- }
- }
- if ($isTmpDirNoCleanEmpty) {
- rmdir($tmpDirNoCleanName);
- }
- }
+ return \OC::$server->getTempManager()->getTemporaryFolder();
}
/**