make sure temporary files are being removed, fixes oc-450
This commit is contained in:
parent
b9f9228a22
commit
b9bdad5165
|
@ -63,7 +63,7 @@ class OC_Files {
|
||||||
$executionTime = intval(ini_get('max_execution_time'));
|
$executionTime = intval(ini_get('max_execution_time'));
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
$zip = new ZipArchive();
|
$zip = new ZipArchive();
|
||||||
$filename = get_temp_dir().'/ownCloud_'.mt_rand(10000,99999).'.zip';
|
$filename = OC_Helper::tmpFile('.zip');
|
||||||
if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==TRUE) {
|
if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==TRUE) {
|
||||||
exit("cannot open <$filename>\n");
|
exit("cannot open <$filename>\n");
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ class OC_Files {
|
||||||
$executionTime = intval(ini_get('max_execution_time'));
|
$executionTime = intval(ini_get('max_execution_time'));
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
$zip = new ZipArchive();
|
$zip = new ZipArchive();
|
||||||
$filename = get_temp_dir().'/ownCloud_'.mt_rand(10000,99999).'.zip';
|
$filename = OC_Helper::tmpFile('.zip');
|
||||||
if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==TRUE) {
|
if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==TRUE) {
|
||||||
exit("cannot open <$filename>\n");
|
exit("cannot open <$filename>\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
class OC_Helper {
|
class OC_Helper {
|
||||||
private static $mimetypes=array();
|
private static $mimetypes=array();
|
||||||
private static $tmpFiles=array();
|
private static $tmpFiles=array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Creates an url
|
* @brief Creates an url
|
||||||
* @param $app app
|
* @param $app app
|
||||||
|
@ -123,7 +123,7 @@ class OC_Helper {
|
||||||
}elseif( file_exists( OC::$SERVERROOT."/core/img/$image" )){
|
}elseif( file_exists( OC::$SERVERROOT."/core/img/$image" )){
|
||||||
return OC::$WEBROOT."/core/img/$image";
|
return OC::$WEBROOT."/core/img/$image";
|
||||||
}else{
|
}else{
|
||||||
echo('image not found: image:'.$image.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
|
echo('image not found: image:'.$image.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ class OC_Helper {
|
||||||
$bytes = round( $bytes / 1024, 1 );
|
$bytes = round( $bytes / 1024, 1 );
|
||||||
return "$bytes GB";
|
return "$bytes GB";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Make a computer file size
|
* @brief Make a computer file size
|
||||||
* @param $str file size in a fancy format
|
* @param $str file size in a fancy format
|
||||||
|
@ -224,9 +224,9 @@ class OC_Helper {
|
||||||
|
|
||||||
$bytes = round($bytes, 2);
|
$bytes = round($bytes, 2);
|
||||||
|
|
||||||
return $bytes;
|
return $bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Recusive editing of file permissions
|
* @brief Recusive editing of file permissions
|
||||||
* @param $path path to file or folder
|
* @param $path path to file or folder
|
||||||
|
@ -276,7 +276,7 @@ class OC_Helper {
|
||||||
copy($src, $dest);
|
copy($src, $dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Recusive deletion of folders
|
* @brief Recusive deletion of folders
|
||||||
* @param string $dir path to the folder
|
* @param string $dir path to the folder
|
||||||
|
@ -294,6 +294,9 @@ class OC_Helper {
|
||||||
}elseif(file_exists($dir)){
|
}elseif(file_exists($dir)){
|
||||||
unlink($dir);
|
unlink($dir);
|
||||||
}
|
}
|
||||||
|
if(file_exists($dir)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -349,7 +352,7 @@ class OC_Helper {
|
||||||
}
|
}
|
||||||
return $mimeType;
|
return $mimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks $_REQUEST contains a var for the $s key. If so, returns the html-escaped value of this var; otherwise returns the default value provided by $d.
|
* @brief Checks $_REQUEST contains a var for the $s key. If so, returns the html-escaped value of this var; otherwise returns the default value provided by $d.
|
||||||
* @param $s name of the var to escape, if set.
|
* @param $s name of the var to escape, if set.
|
||||||
|
@ -357,16 +360,16 @@ class OC_Helper {
|
||||||
* @returns the print-safe value.
|
* @returns the print-safe value.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//FIXME: should also check for value validation (i.e. the email is an email).
|
//FIXME: should also check for value validation (i.e. the email is an email).
|
||||||
public static function init_var($s, $d="") {
|
public static function init_var($s, $d="") {
|
||||||
$r = $d;
|
$r = $d;
|
||||||
if(isset($_REQUEST[$s]) && !empty($_REQUEST[$s]))
|
if(isset($_REQUEST[$s]) && !empty($_REQUEST[$s]))
|
||||||
$r = stripslashes(htmlspecialchars($_REQUEST[$s]));
|
$r = stripslashes(htmlspecialchars($_REQUEST[$s]));
|
||||||
|
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns "checked"-attribut if request contains selected radio element OR if radio element is the default one -- maybe?
|
* returns "checked"-attribut if request contains selected radio element OR if radio element is the default one -- maybe?
|
||||||
* @param string $s Name of radio-button element name
|
* @param string $s Name of radio-button element name
|
||||||
|
@ -422,7 +425,7 @@ class OC_Helper {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* copy the contents of one stream to another
|
* copy the contents of one stream to another
|
||||||
* @param resource source
|
* @param resource source
|
||||||
|
@ -439,7 +442,7 @@ class OC_Helper {
|
||||||
}
|
}
|
||||||
return $count;
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a temporary file with an unique filename
|
* create a temporary file with an unique filename
|
||||||
* @param string postfix
|
* @param string postfix
|
||||||
|
@ -467,14 +470,25 @@ class OC_Helper {
|
||||||
self::$tmpFiles[]=$path;
|
self::$tmpFiles[]=$path;
|
||||||
return $path.'/';
|
return $path.'/';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove all files created by self::tmpFile
|
* remove all files created by self::tmpFile
|
||||||
*/
|
*/
|
||||||
public static function cleanTmp(){
|
public static function cleanTmp(){
|
||||||
|
$leftoversFile='/tmp/oc-not-deleted';
|
||||||
|
if(file_exists($leftoversFile)){
|
||||||
|
$leftovers=file($leftoversFile);
|
||||||
|
foreach($leftovers as $file) {
|
||||||
|
self::rmdirr($file);
|
||||||
|
}
|
||||||
|
unlink($leftoversFile);
|
||||||
|
}
|
||||||
|
|
||||||
foreach(self::$tmpFiles as $file){
|
foreach(self::$tmpFiles as $file){
|
||||||
if(file_exists($file)){
|
if(file_exists($file)){
|
||||||
self::rmdirr($file);
|
if(!self::rmdirr($file)) {
|
||||||
|
file_put_contents($leftoversFile, $file."\n", FILE_APPEND);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue