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
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-11-17 18:45:54 +0300
committerVincent Petry <pvince81@owncloud.com>2014-11-17 18:45:54 +0300
commitaf7688ec17c260d3e227393e8e81438fe88b956c (patch)
tree210de64fa88c25d736ff20dc7d4472fb824920f5 /lib/private/preview.php
parent146cb920c9daba10da0bd93efab3e64df97224de (diff)
parent33186957c8e20aa8fd7ac6aa75e7f8ef98b4df9a (diff)
Merge pull request #11741 from owncloud/delete_all_children_preview_2
delete all children's previews when deleting a folder
Diffstat (limited to 'lib/private/preview.php')
-rw-r--r--lib/private/preview.php110
1 files changed, 94 insertions, 16 deletions
diff --git a/lib/private/preview.php b/lib/private/preview.php
index dbbe173bf80..f50bdcb4c9e 100644
--- a/lib/private/preview.php
+++ b/lib/private/preview.php
@@ -48,6 +48,7 @@ class Preview {
//filemapper used for deleting previews
// index is path, value is fileinfo
static public $deleteFileMapper = array();
+ static public $deleteChildrenMapper = array();
/**
* preview images object
@@ -189,6 +190,21 @@ class Preview {
return $this->info;
}
+
+ /**
+ * @return array|null
+ */
+ private function getChildren() {
+ $absPath = $this->fileView->getAbsolutePath($this->file);
+ $absPath = Files\Filesystem::normalizePath($absPath);
+
+ if (array_key_exists($absPath, self::$deleteChildrenMapper)) {
+ return self::$deleteChildrenMapper[$absPath];
+ }
+
+ return null;
+ }
+
/**
* set the path of the file you want a thumbnail from
* @param string $file
@@ -269,6 +285,10 @@ class Preview {
return $this;
}
+ /**
+ * @param bool $keepAspect
+ * @return $this
+ */
public function setKeepAspect($keepAspect) {
$this->keepAspect = $keepAspect;
return $this;
@@ -312,20 +332,25 @@ class Preview {
/**
* deletes all previews of a file
- * @return bool
*/
public function deleteAllPreviews() {
$file = $this->getFile();
$fileInfo = $this->getFileInfo($file);
- if($fileInfo !== null && $fileInfo !== false) {
- $fileId = $fileInfo->getId();
- $previewPath = $this->getPreviewPath($fileId);
- $this->userView->deleteAll($previewPath);
- return $this->userView->rmdir($previewPath);
+ $toDelete = $this->getChildren();
+ $toDelete[] = $fileInfo;
+
+ foreach ($toDelete as $delete) {
+ if ($delete !== null && $delete !== false) {
+ /** @var \OCP\Files\FileInfo $delete */
+ $fileId = $delete->getId();
+
+ $previewPath = $this->getPreviewPath($fileId);
+ $this->userView->deleteAll($previewPath);
+ $this->userView->rmdir($previewPath);
+ }
}
- return false;
}
/**
@@ -667,8 +692,8 @@ class Preview {
}
/**
- * Register a new preview provider to be used
- * @param $class
+ * register a new preview provider to be used
+ * @param string $class
* @param array $options
*/
public static function registerProvider($class, $options = array()) {
@@ -737,14 +762,24 @@ class Preview {
}
+ /**
+ * @param array $args
+ */
public static function post_write($args) {
self::post_delete($args, 'files/');
}
+ /**
+ * @param array $args
+ */
public static function prepare_delete_files($args) {
self::prepare_delete($args, 'files/');
}
+ /**
+ * @param array $args
+ * @param string $prefix
+ */
public static function prepare_delete($args, $prefix='') {
$path = $args['path'];
if (substr($path, 0, 1) === '/') {
@@ -752,20 +787,63 @@ class Preview {
}
$view = new \OC\Files\View('/' . \OC_User::getUser() . '/' . $prefix);
- $info = $view->getFileInfo($path);
- \OC\Preview::$deleteFileMapper = array_merge(
- \OC\Preview::$deleteFileMapper,
- array(
- Files\Filesystem::normalizePath($view->getAbsolutePath($path)) => $info,
- )
- );
+ $absPath = Files\Filesystem::normalizePath($view->getAbsolutePath($path));
+ self::addPathToDeleteFileMapper($absPath, $view->getFileInfo($path));
+ if ($view->is_dir($path)) {
+ $children = self::getAllChildren($view, $path);
+ self::$deleteChildrenMapper[$absPath] = $children;
+ }
+ }
+
+ /**
+ * @param string $absolutePath
+ * @param \OCP\Files\FileInfo $info
+ */
+ private static function addPathToDeleteFileMapper($absolutePath, $info) {
+ self::$deleteFileMapper[$absolutePath] = $info;
+ }
+
+ /**
+ * @param \OC\Files\View $view
+ * @param string $path
+ * @return array
+ */
+ private static function getAllChildren($view, $path) {
+ $children = $view->getDirectoryContent($path);
+ $childrensFiles = array();
+
+ $fakeRootLength = strlen($view->getRoot());
+
+ for ($i = 0; $i < count($children); $i++) {
+ $child = $children[$i];
+
+ $childsPath = substr($child->getPath(), $fakeRootLength);
+
+ if ($view->is_dir($childsPath)) {
+ $children = array_merge(
+ $children,
+ $view->getDirectoryContent($childsPath)
+ );
+ } else {
+ $childrensFiles[] = $child;
+ }
+ }
+
+ return $childrensFiles;
}
+ /**
+ * @param array $args
+ */
public static function post_delete_files($args) {
self::post_delete($args, 'files/');
}
+ /**
+ * @param array $args
+ * @param string $prefix
+ */
public static function post_delete($args, $prefix='') {
$path = Files\Filesystem::normalizePath($args['path']);