diff options
author | Brice Maron <brice@bmaron.net> | 2012-06-21 20:19:31 +0000 |
---|---|---|
committer | Brice Maron <brice@bmaron.net> | 2012-06-21 20:19:31 +0000 |
commit | a5938e4e3766bb7502a3493661ed3bac662f5182 (patch) | |
tree | 02fcbe206788e471f122158730004554afec83c5 /lib | |
parent | 84b9ac2678e6a0b014b730896a12d1531789d8da (diff) | |
parent | 37d12144c2debd27271378d2adc5c2b65a25e1f7 (diff) | |
download | nextcloud-server-a5938e4e3766bb7502a3493661ed3bac662f5182.tar.gz nextcloud-server-a5938e4e3766bb7502a3493661ed3bac662f5182.zip |
Merge branch 'master' into multi_app_dir
Diffstat (limited to 'lib')
-rw-r--r-- | lib/filestorage/common.php | 85 | ||||
-rw-r--r-- | lib/filestorage/local.php | 4 | ||||
-rw-r--r-- | lib/filesystemview.php | 3 |
3 files changed, 90 insertions, 2 deletions
diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index f2a5775fd19..ba78fca80e5 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -20,6 +20,18 @@ * License along with this library. If not, see <http://www.gnu.org/licenses/>. */ +/** + * Storage backend class for providing common filesystem operation methods + * which are not storage-backend specific. + * + * OC_Filestorage_Common is never used directly; it is extended by all other + * storage backends, where its methods may be overridden, and additional + * (backend-specific) methods are defined. + * + * Some OC_Filestorage_Common methods call functions which are first defined + * in classes which extend it, e.g. $this->stat() . + */ + abstract class OC_Filestorage_Common extends OC_Filestorage { public function __construct($parameters){} @@ -87,6 +99,79 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { return $count>0; } // abstract public function fopen($path,$mode); + + /** + * @brief Deletes all files and folders recursively within a directory + * @param $directory The directory whose contents will be deleted + * @param $empty Flag indicating whether directory will be emptied + * @returns true/false + * + * @note By default the directory specified by $directory will be + * deleted together with its contents. To avoid this set $empty to true + */ + public function deleteAll( $directory, $empty = false ) { + + // strip leading slash + if( substr( $directory, 0, 1 ) == "/" ) { + + $directory = substr( $directory, 1 ); + + } + + // strip trailing slash + if( substr( $directory, -1) == "/" ) { + + $directory = substr( $directory, 0, -1 ); + + } + + if ( !$this->file_exists( \OCP\USER::getUser() . '/' . $directory ) || !$this->is_dir( \OCP\USER::getUser() . '/' . $directory ) ) { + + return false; + + } elseif( !$this->is_readable( \OCP\USER::getUser() . '/' . $directory ) ) { + + return false; + + } else { + + $directoryHandle = $this->opendir( \OCP\USER::getUser() . '/' . $directory ); + + while ( $contents = readdir( $directoryHandle ) ) { + + if ( $contents != '.' && $contents != '..') { + + $path = $directory . "/" . $contents; + + if ( $this->is_dir( $path ) ) { + + deleteAll( $path ); + + } else { + + $this->unlink( \OCP\USER::getUser() .'/' . $path ); // TODO: make unlink use same system path as is_dir + + } + } + + } + + //$this->closedir( $directoryHandle ); // TODO: implement closedir in OC_FSV + + if ( $empty == false ) { + + if ( !$this->rmdir( $directory ) ) { + + return false; + + } + + } + + return true; + } + + } public function getMimeType($path){ if(!$this->file_exists($path)){ return false; diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index 44a2ab0f634..b2eba051515 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -2,7 +2,7 @@ /** * for local filestore, we only have to map the paths */ -class OC_Filestorage_Local extends OC_Filestorage{ +class OC_Filestorage_Local extends OC_Filestorage_Common{ protected $datadir; private static $mimetypes=null; public function __construct($arguments){ @@ -172,7 +172,7 @@ class OC_Filestorage_Local extends OC_Filestorage{ return $this->datadir.$path; } - private function searchInDir($query,$dir=''){ + protected function searchInDir($query,$dir=''){ $files=array(); foreach (scandir($this->datadir.$dir) as $item) { if ($item == '.' || $item == '..') continue; diff --git a/lib/filesystemview.php b/lib/filesystemview.php index da622bcf920..99e08c50e75 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -252,6 +252,9 @@ class OC_FilesystemView { public function unlink($path){ return $this->basicOperation('unlink',$path,array('delete')); } + public function deleteAll( $directory, $empty = false ) { + return $this->basicOperation( 'deleteAll', $directory, array('delete'), $empty ); + } public function rename($path1,$path2){ $absolutePath1=$this->getAbsolutePath($path1); $absolutePath2=$this->getAbsolutePath($path2); |