From b9d5c312117d350f6c2d65c0b934c6df818e7bc1 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Sat, 16 Nov 2024 09:50:42 +0100 Subject: [PATCH] move rrmdir() into own class in inc.Utils.php --- inc/inc.ClassExtensionMgr.php | 23 +++++------------------ inc/inc.Utils.php | 28 ++++++++++++++++++++++++++++ op/op.ImportFS.php | 7 ++++--- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/inc/inc.ClassExtensionMgr.php b/inc/inc.ClassExtensionMgr.php index 22eda0f75..fc5eceebd 100644 --- a/inc/inc.ClassExtensionMgr.php +++ b/inc/inc.ClassExtensionMgr.php @@ -490,19 +490,6 @@ class SeedDMS_Extension_Mgr { return $this->configcache[$extname]; } /* }}} */ - static protected function rrmdir($dir) { /* {{{ */ - if (is_dir($dir)) { - $objects = scandir($dir); - foreach ($objects as $object) { - if ($object != "." && $object != "..") { - if (filetype($dir."/".$object) == "dir") self::rrmdir($dir."/".$object); else unlink($dir."/".$object); - } - } - reset($objects); - rmdir($dir); - } - } /* }}} */ - /** * Update an extension * @@ -518,7 +505,7 @@ class SeedDMS_Extension_Mgr { $newdir = addDirSep($this->cachedir)."ext.new"; /* First remove a left over from a previous extension */ if(file_exists($newdir)) { - self::rrmdir($newdir); + SeedDMS_Utils::rrmdir($newdir); } if(!mkdir($newdir, 0755)) { $this->errmsgs[] = "Cannot create temp. extension directory"; @@ -538,7 +525,7 @@ class SeedDMS_Extension_Mgr { /* Check if extension is complete and fullfills the constraints */ if(!self::checkExtensionByDir($newdir)) { - self::rrmdir($newdir); + SeedDMS_Utils::rrmdir($newdir); return false; } @@ -549,11 +536,11 @@ class SeedDMS_Extension_Mgr { if(!is_dir($this->extdir)) { if(!mkdir($this->extdir, 0755)) { $this->errmsgs[] = "Cannot create extension directory"; - self::rrmdir($newdir); + SeedDMS_Utils::rrmdir($newdir); return false; } } elseif(is_dir($this->extdir ."/". $extname)) { - $this->rrmdir($this->extdir ."/". $extname); + SeedDMS_Utils::rrmdir($this->extdir ."/". $extname); } /* Move the temp. created ext directory to the final location */ /* rename() may fail if dirs are moved from one device to another. @@ -575,7 +562,7 @@ class SeedDMS_Extension_Mgr { * has been copied. */ $this->errmsgs[] = "Cannot move temp. extension directory to final destination"; - $this->rrmdir($this->extdir ."/". $extname); + SeedDMS_Utils::rrmdir($this->extdir ."/". $extname); return false; } diff --git a/inc/inc.Utils.php b/inc/inc.Utils.php index 5449e176b..d42938604 100644 --- a/inc/inc.Utils.php +++ b/inc/inc.Utils.php @@ -1231,6 +1231,34 @@ function getMandatoryApprovers($folder, $document, $user) { /* {{{ */ return $approvers; } /* }}} */ +/** + * Class with various utility methods + * + * This class will sooner or later comprise the functions above + * + */ +class SeedDMS_Utils { /* {{{ */ + + /** + * Recursively remove a directory on disc + * + * @param string $dir name of directory + */ + static public function rrmdir($dir) { /* {{{ */ + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { + if ($object != "." && $object != "..") { + if (filetype($dir."/".$object) == "dir") self::rrmdir($dir."/".$object); else unlink($dir."/".$object); + } + } + reset($objects); + rmdir($dir); + } + } /* }}} */ + +} /* }}} */ + /** * Class for creating encrypted api keys * diff --git a/op/op.ImportFS.php b/op/op.ImportFS.php index d5f3f90c2..0ebd62aa5 100644 --- a/op/op.ImportFS.php +++ b/op/op.ImportFS.php @@ -239,9 +239,10 @@ if($newfolder) { $session->setSplashMsg(array('type'=>'error', 'msg'=>getMLText('error_importfs'))); else { if(isset($_GET['remove']) && $_GET["remove"]) { - $cmd = 'rm -rf '.$dirname; - $ret = null; - system($cmd, $ret); + SeedDMS_Utils::rrmdir($dirname); +// $cmd = 'rm -rf '.$dirname; +// $ret = null; +// system($cmd, $ret); } $session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_importfs', array('docs'=>$doccount, 'folders'=>$foldercount)))); }