diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-01-27 17:05:38 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-01-27 17:05:38 +0100 |
commit | acec40fe5aea032b9ee81116c721848d1d37355f (patch) | |
tree | 26fb4e56ec10fff43df1eef23f27881ce9a543da /lib | |
parent | 3478634df1ce2b7717bfe211425f59c4107688f8 (diff) | |
parent | 12867b9c788487aa67ebfb4f8ee1e9997877ee69 (diff) | |
download | nextcloud-server-acec40fe5aea032b9ee81116c721848d1d37355f.tar.gz nextcloud-server-acec40fe5aea032b9ee81116c721848d1d37355f.zip |
Merge pull request #13561 from owncloud/trash-finaldeletewhencrossstoragefix
Call final unlink in trash wrapper's storage
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/files/filesystem.php | 17 | ||||
-rw-r--r-- | lib/private/files/storage/storagefactory.php | 30 | ||||
-rw-r--r-- | lib/private/files/view.php | 13 | ||||
-rw-r--r-- | lib/public/files/storage/istoragefactory.php | 2 |
4 files changed, 52 insertions, 10 deletions
diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php index f90b2738d03..c460159ece3 100644 --- a/lib/private/files/filesystem.php +++ b/lib/private/files/filesystem.php @@ -175,14 +175,18 @@ class Filesystem { * @param callable $wrapper */ public static function addStorageWrapper($wrapperName, $wrapper) { - self::getLoader()->addStorageWrapper($wrapperName, $wrapper); - $mounts = self::getMountManager()->getAll(); - foreach ($mounts as $mount) { - $mount->wrapStorage($wrapper); + if (!self::getLoader()->addStorageWrapper($wrapperName, $wrapper, $mounts)) { + // do not re-wrap if storage with this name already existed + return; } } + /** + * Returns the storage factory + * + * @return \OCP\Files\Storage\IStorageFactory + */ public static function getLoader() { if (!self::$loader) { self::$loader = new StorageFactory(); @@ -190,6 +194,11 @@ class Filesystem { return self::$loader; } + /** + * Returns the mount manager + * + * @return \OC\Files\Mount\Manager + */ public static function getMountManager() { if (!self::$mounts) { \OC_Util::setupFS(); diff --git a/lib/private/files/storage/storagefactory.php b/lib/private/files/storage/storagefactory.php index c9e8d422f9d..fa6dea2537c 100644 --- a/lib/private/files/storage/storagefactory.php +++ b/lib/private/files/storage/storagefactory.php @@ -21,11 +21,35 @@ class StorageFactory implements IStorageFactory { * * $callback should be a function of type (string $mountPoint, Storage $storage) => Storage * - * @param string $wrapperName - * @param callable $callback + * @param string $wrapperName name of the wrapper + * @param callable $callback callback + * @param \OCP\Files\Mount\IMountPoint[] $existingMounts existing mount points to apply the wrapper to + * @return bool true if the wrapper was added, false if there was already a wrapper with this + * name registered */ - public function addStorageWrapper($wrapperName, $callback) { + public function addStorageWrapper($wrapperName, $callback, $existingMounts = []) { + if (isset($this->storageWrappers[$wrapperName])) { + return false; + } + + // apply to existing mounts before registering it to prevent applying it double in MountPoint::createStorage + foreach ($existingMounts as $mount) { + $mount->wrapStorage($callback); + } + $this->storageWrappers[$wrapperName] = $callback; + return true; + } + + /** + * Remove a storage wrapper by name. + * Note: internal method only to be used for cleanup + * + * @param string $wrapperName name of the wrapper + * @internal + */ + public function removeStorageWrapper($wrapperName) { + unset($this->storageWrappers[$wrapperName]); } /** diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 76b7d34e756..f466361bd02 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -511,7 +511,7 @@ class View { } } else { if ($this->is_dir($path1)) { - $result = $this->copy($path1, $path2); + $result = $this->copy($path1, $path2, true); if ($result === true) { $result = $storage1->rmdir($internalPath1); } @@ -519,6 +519,7 @@ class View { $source = $this->fopen($path1 . $postFix1, 'r'); $target = $this->fopen($path2 . $postFix2, 'w'); list($count, $result) = \OC_Helper::streamCopy($source, $target); + $this->touch($path2, $this->filemtime($path1)); // close open handle - especially $source is necessary because unlink below will // throw an exception on windows because the file is locked @@ -556,7 +557,7 @@ class View { } } - public function copy($path1, $path2) { + public function copy($path1, $path2, $preserveMtime = false) { $postFix1 = (substr($path1, -1, 1) === '/') ? '/' : ''; $postFix2 = (substr($path2, -1, 1) === '/') ? '/' : ''; $absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1)); @@ -601,10 +602,13 @@ class View { } else { if ($this->is_dir($path1) && ($dh = $this->opendir($path1))) { $result = $this->mkdir($path2); + if ($preserveMtime) { + $this->touch($path2, $this->filemtime($path1)); + } if (is_resource($dh)) { while (($file = readdir($dh)) !== false) { if (!Filesystem::isIgnoredDir($file)) { - $result = $this->copy($path1 . '/' . $file, $path2 . '/' . $file); + $result = $this->copy($path1 . '/' . $file, $path2 . '/' . $file, $preserveMtime); } } } @@ -612,6 +616,9 @@ class View { $source = $this->fopen($path1 . $postFix1, 'r'); $target = $this->fopen($path2 . $postFix2, 'w'); list($count, $result) = \OC_Helper::streamCopy($source, $target); + if($preserveMtime) { + $this->touch($path2, $this->filemtime($path1)); + } fclose($source); fclose($target); } diff --git a/lib/public/files/storage/istoragefactory.php b/lib/public/files/storage/istoragefactory.php index 769d7011de4..50c844af2e6 100644 --- a/lib/public/files/storage/istoragefactory.php +++ b/lib/public/files/storage/istoragefactory.php @@ -19,6 +19,8 @@ interface IStorageFactory { * * @param string $wrapperName * @param callable $callback + * @return bool true if the wrapper was added, false if there was already a wrapper with this + * name registered */ public function addStorageWrapper($wrapperName, $callback); |