| @@ -38,282 +38,282 @@ | ||
| 38 | 38 | |
| 39 | 39 |  class Storage extends Wrapper { | 
| 40 | 40 | |
| 41 | - private $mountPoint; | |
| 42 | - // remember already deleted files to avoid infinite loops if the trash bin | |
| 43 | - // move files across storages | |
| 44 | - private $deletedFiles = array(); | |
| 45 | - | |
| 46 | - /** | |
| 47 | - * Disable trash logic | |
| 48 | - * | |
| 49 | - * @var bool | |
| 50 | - */ | |
| 51 | - private static $disableTrash = false; | |
| 52 | - | |
| 53 | - /** | |
| 54 | - * remember which file/folder was moved out of s shared folder | |
| 55 | - * in this case we want to add a copy to the owners trash bin | |
| 56 | - * | |
| 57 | - * @var array | |
| 58 | - */ | |
| 59 | - private static $moveOutOfSharedFolder = []; | |
| 60 | - | |
| 61 | - /** @var IUserManager */ | |
| 62 | - private $userManager; | |
| 63 | - | |
| 64 | - /** @var ILogger */ | |
| 65 | - private $logger; | |
| 66 | - | |
| 67 | - /** @var EventDispatcher */ | |
| 68 | - private $eventDispatcher; | |
| 69 | - | |
| 70 | - /** @var IRootFolder */ | |
| 71 | - private $rootFolder; | |
| 72 | - | |
| 73 | - /** | |
| 74 | - * Storage constructor. | |
| 75 | - * | |
| 76 | - * @param array $parameters | |
| 77 | - * @param IUserManager|null $userManager | |
| 78 | - * @param ILogger|null $logger | |
| 79 | - * @param EventDispatcher|null $eventDispatcher | |
| 80 | - * @param IRootFolder|null $rootFolder | |
| 81 | - */ | |
| 82 | - public function __construct($parameters, | |
| 83 | - IUserManager $userManager = null, | |
| 84 | - ILogger $logger = null, | |
| 85 | - EventDispatcher $eventDispatcher = null, | |
| 86 | -								IRootFolder $rootFolder = null) { | |
| 87 | - $this->mountPoint = $parameters['mountPoint']; | |
| 88 | - $this->userManager = $userManager; | |
| 89 | - $this->logger = $logger; | |
| 90 | - $this->eventDispatcher = $eventDispatcher; | |
| 91 | - $this->rootFolder = $rootFolder; | |
| 92 | - parent::__construct($parameters); | |
| 93 | - } | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * @internal | |
| 97 | - */ | |
| 98 | -	public static function preRenameHook($params) { | |
| 99 | - // in cross-storage cases, a rename is a copy + unlink, | |
| 100 | - // that last unlink must not go to trash, only exception: | |
| 101 | - // if the file was moved from a shared storage to a local folder, | |
| 102 | - // in this case the owner should get a copy in his trash bin so that | |
| 103 | - // they can restore the files again | |
| 104 | - | |
| 105 | - $oldPath = $params['oldpath']; | |
| 106 | - $newPath = dirname($params['newpath']); | |
| 107 | - $currentUser = \OC::$server->getUserSession()->getUser(); | |
| 108 | - | |
| 109 | - $fileMovedOutOfSharedFolder = false; | |
| 110 | - | |
| 111 | -		try { | |
| 112 | -			if ($currentUser) { | |
| 113 | - $currentUserId = $currentUser->getUID(); | |
| 114 | - | |
| 115 | - $view = new View($currentUserId . '/files'); | |
| 116 | - $fileInfo = $view->getFileInfo($oldPath); | |
| 117 | -				if ($fileInfo) { | |
| 118 | - $sourceStorage = $fileInfo->getStorage(); | |
| 119 | - $sourceOwner = $view->getOwner($oldPath); | |
| 120 | - $targetOwner = $view->getOwner($newPath); | |
| 121 | - | |
| 122 | - if ($sourceOwner !== $targetOwner | |
| 123 | -						&& $sourceStorage->instanceOfStorage('OCA\Files_Sharing\SharedStorage') | |
| 124 | -					) { | |
| 125 | - $fileMovedOutOfSharedFolder = true; | |
| 126 | - } | |
| 127 | - } | |
| 128 | - } | |
| 129 | -		} catch (\Exception $e) { | |
| 130 | - // do nothing, in this case we just disable the trashbin and continue | |
| 131 | - $logger = \OC::$server->getLogger(); | |
| 132 | -			$logger->debug('Trashbin storage could not check if a file was moved out of a shared folder: ' . $e->getMessage()); | |
| 133 | - } | |
| 134 | - | |
| 135 | -		if($fileMovedOutOfSharedFolder) { | |
| 136 | - self::$moveOutOfSharedFolder['/' . $currentUserId . '/files' . $oldPath] = true; | |
| 137 | -		} else { | |
| 138 | - self::$disableTrash = true; | |
| 139 | - } | |
| 140 | - | |
| 141 | - } | |
| 142 | - | |
| 143 | - /** | |
| 144 | - * @internal | |
| 145 | - */ | |
| 146 | -	public static function postRenameHook($params) { | |
| 147 | - self::$disableTrash = false; | |
| 148 | - } | |
| 149 | - | |
| 150 | - /** | |
| 151 | - * Rename path1 to path2 by calling the wrapped storage. | |
| 152 | - * | |
| 153 | - * @param string $path1 first path | |
| 154 | - * @param string $path2 second path | |
| 155 | - * @return bool | |
| 156 | - */ | |
| 157 | -	public function rename($path1, $path2) { | |
| 158 | - $result = $this->storage->rename($path1, $path2); | |
| 159 | -		if ($result === false) { | |
| 160 | - // when rename failed, the post_rename hook isn't triggered, | |
| 161 | - // but we still want to reenable the trash logic | |
| 162 | - self::$disableTrash = false; | |
| 163 | - } | |
| 164 | - return $result; | |
| 165 | - } | |
| 166 | - | |
| 167 | - /** | |
| 168 | - * Deletes the given file by moving it into the trashbin. | |
| 169 | - * | |
| 170 | - * @param string $path path of file or folder to delete | |
| 171 | - * | |
| 172 | - * @return bool true if the operation succeeded, false otherwise | |
| 173 | - */ | |
| 174 | -	public function unlink($path) { | |
| 175 | -		try { | |
| 176 | -			if (isset(self::$moveOutOfSharedFolder[$this->mountPoint . $path])) { | |
| 177 | - $result = $this->doDelete($path, 'unlink', true); | |
| 178 | - unset(self::$moveOutOfSharedFolder[$this->mountPoint . $path]); | |
| 179 | -			} else { | |
| 180 | - $result = $this->doDelete($path, 'unlink'); | |
| 181 | - } | |
| 182 | -		} catch (GenericEncryptionException $e) { | |
| 183 | - // in case of a encryption exception we delete the file right away | |
| 184 | - $this->logger->info( | |
| 185 | - "Can't move file" . $path . | |
| 186 | - "to the trash bin, therefore it was deleted right away"); | |
| 187 | - | |
| 188 | - $result = $this->storage->unlink($path); | |
| 189 | - } | |
| 190 | - | |
| 191 | - return $result; | |
| 192 | - } | |
| 193 | - | |
| 194 | - /** | |
| 195 | - * Deletes the given folder by moving it into the trashbin. | |
| 196 | - * | |
| 197 | - * @param string $path path of folder to delete | |
| 198 | - * | |
| 199 | - * @return bool true if the operation succeeded, false otherwise | |
| 200 | - */ | |
| 201 | -	public function rmdir($path) { | |
| 202 | -		if (isset(self::$moveOutOfSharedFolder[$this->mountPoint . $path])) { | |
| 203 | - $result = $this->doDelete($path, 'rmdir', true); | |
| 204 | - unset(self::$moveOutOfSharedFolder[$this->mountPoint . $path]); | |
| 205 | -		} else { | |
| 206 | - $result = $this->doDelete($path, 'rmdir'); | |
| 207 | - } | |
| 208 | - | |
| 209 | - return $result; | |
| 210 | - } | |
| 211 | - | |
| 212 | - /** | |
| 213 | - * check if it is a file located in data/user/files only files in the | |
| 214 | - * 'files' directory should be moved to the trash | |
| 215 | - * | |
| 216 | - * @param $path | |
| 217 | - * @return bool | |
| 218 | - */ | |
| 219 | -	protected function shouldMoveToTrash($path){ | |
| 220 | - | |
| 221 | - // check if there is a app which want to disable the trash bin for this file | |
| 222 | - $fileId = $this->storage->getCache()->getId($path); | |
| 223 | - $nodes = $this->rootFolder->getById($fileId); | |
| 224 | -		foreach ($nodes as $node) { | |
| 225 | - $event = $this->createMoveToTrashEvent($node); | |
| 226 | -			$this->eventDispatcher->dispatch('OCA\Files_Trashbin::moveToTrash', $event); | |
| 227 | -			if ($event->shouldMoveToTrashBin() === false) { | |
| 228 | - return false; | |
| 229 | - } | |
| 230 | - } | |
| 231 | - | |
| 232 | - $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path); | |
| 233 | -		$parts = explode('/', $normalized); | |
| 234 | -		if (count($parts) < 4) { | |
| 235 | - return false; | |
| 236 | - } | |
| 237 | - | |
| 238 | -		if ($this->userManager->userExists($parts[1]) && $parts[2] === 'files') { | |
| 239 | - return true; | |
| 240 | - } | |
| 241 | - | |
| 242 | - return false; | |
| 243 | - } | |
| 244 | - | |
| 245 | - /** | |
| 246 | - * get move to trash event | |
| 247 | - * | |
| 248 | - * @param Node $node | |
| 249 | - * @return MoveToTrashEvent | |
| 250 | - */ | |
| 251 | -	protected function createMoveToTrashEvent(Node $node) { | |
| 252 | - $event = new MoveToTrashEvent($node); | |
| 253 | - return $event; | |
| 254 | - } | |
| 255 | - | |
| 256 | - /** | |
| 257 | - * Run the delete operation with the given method | |
| 258 | - * | |
| 259 | - * @param string $path path of file or folder to delete | |
| 260 | - * @param string $method either "unlink" or "rmdir" | |
| 261 | - * @param bool $ownerOnly delete for owner only (if file gets moved out of a shared folder) | |
| 262 | - * | |
| 263 | - * @return bool true if the operation succeeded, false otherwise | |
| 264 | - */ | |
| 265 | -	private function doDelete($path, $method, $ownerOnly = false) { | |
| 266 | - if (self::$disableTrash | |
| 267 | -			|| !\OC_App::isEnabled('files_trashbin') | |
| 268 | - || (pathinfo($path, PATHINFO_EXTENSION) === 'part') | |
| 269 | - || $this->shouldMoveToTrash($path) === false | |
| 270 | -		) { | |
| 271 | - return call_user_func_array([$this->storage, $method], [$path]); | |
| 272 | - } | |
| 273 | - | |
| 274 | - // check permissions before we continue, this is especially important for | |
| 275 | - // shared files | |
| 276 | -		if (!$this->isDeletable($path)) { | |
| 277 | - return false; | |
| 278 | - } | |
| 279 | - | |
| 280 | - $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path, true, false, true); | |
| 281 | - $result = true; | |
| 282 | - $view = Filesystem::getView(); | |
| 283 | -		if (!isset($this->deletedFiles[$normalized]) && $view instanceof View) { | |
| 284 | - $this->deletedFiles[$normalized] = $normalized; | |
| 285 | -			if ($filesPath = $view->getRelativePath($normalized)) { | |
| 286 | - $filesPath = trim($filesPath, '/'); | |
| 287 | - $result = \OCA\Files_Trashbin\Trashbin::move2trash($filesPath, $ownerOnly); | |
| 288 | - // in cross-storage cases the file will be copied | |
| 289 | - // but not deleted, so we delete it here | |
| 290 | -				if ($result) { | |
| 291 | - call_user_func_array([$this->storage, $method], [$path]); | |
| 292 | - } | |
| 293 | -			} else { | |
| 294 | - $result = call_user_func_array([$this->storage, $method], [$path]); | |
| 295 | - } | |
| 296 | - unset($this->deletedFiles[$normalized]); | |
| 297 | -		} else if ($this->storage->file_exists($path)) { | |
| 298 | - $result = call_user_func_array([$this->storage, $method], [$path]); | |
| 299 | - } | |
| 300 | - | |
| 301 | - return $result; | |
| 302 | - } | |
| 303 | - | |
| 304 | - /** | |
| 305 | - * Setup the storate wrapper callback | |
| 306 | - */ | |
| 307 | -	public static function setupStorage() { | |
| 308 | -		\OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) { | |
| 309 | - return new \OCA\Files_Trashbin\Storage( | |
| 310 | -				array('storage' => $storage, 'mountPoint' => $mountPoint), | |
| 311 | - \OC::$server->getUserManager(), | |
| 312 | - \OC::$server->getLogger(), | |
| 313 | - \OC::$server->getEventDispatcher(), | |
| 314 | - \OC::$server->getLazyRootFolder() | |
| 315 | - ); | |
| 316 | - }, 1); | |
| 317 | - } | |
| 41 | + private $mountPoint; | |
| 42 | + // remember already deleted files to avoid infinite loops if the trash bin | |
| 43 | + // move files across storages | |
| 44 | + private $deletedFiles = array(); | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Disable trash logic | |
| 48 | + * | |
| 49 | + * @var bool | |
| 50 | + */ | |
| 51 | + private static $disableTrash = false; | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * remember which file/folder was moved out of s shared folder | |
| 55 | + * in this case we want to add a copy to the owners trash bin | |
| 56 | + * | |
| 57 | + * @var array | |
| 58 | + */ | |
| 59 | + private static $moveOutOfSharedFolder = []; | |
| 60 | + | |
| 61 | + /** @var IUserManager */ | |
| 62 | + private $userManager; | |
| 63 | + | |
| 64 | + /** @var ILogger */ | |
| 65 | + private $logger; | |
| 66 | + | |
| 67 | + /** @var EventDispatcher */ | |
| 68 | + private $eventDispatcher; | |
| 69 | + | |
| 70 | + /** @var IRootFolder */ | |
| 71 | + private $rootFolder; | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * Storage constructor. | |
| 75 | + * | |
| 76 | + * @param array $parameters | |
| 77 | + * @param IUserManager|null $userManager | |
| 78 | + * @param ILogger|null $logger | |
| 79 | + * @param EventDispatcher|null $eventDispatcher | |
| 80 | + * @param IRootFolder|null $rootFolder | |
| 81 | + */ | |
| 82 | + public function __construct($parameters, | |
| 83 | + IUserManager $userManager = null, | |
| 84 | + ILogger $logger = null, | |
| 85 | + EventDispatcher $eventDispatcher = null, | |
| 86 | +                                IRootFolder $rootFolder = null) { | |
| 87 | + $this->mountPoint = $parameters['mountPoint']; | |
| 88 | + $this->userManager = $userManager; | |
| 89 | + $this->logger = $logger; | |
| 90 | + $this->eventDispatcher = $eventDispatcher; | |
| 91 | + $this->rootFolder = $rootFolder; | |
| 92 | + parent::__construct($parameters); | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * @internal | |
| 97 | + */ | |
| 98 | +    public static function preRenameHook($params) { | |
| 99 | + // in cross-storage cases, a rename is a copy + unlink, | |
| 100 | + // that last unlink must not go to trash, only exception: | |
| 101 | + // if the file was moved from a shared storage to a local folder, | |
| 102 | + // in this case the owner should get a copy in his trash bin so that | |
| 103 | + // they can restore the files again | |
| 104 | + | |
| 105 | + $oldPath = $params['oldpath']; | |
| 106 | + $newPath = dirname($params['newpath']); | |
| 107 | + $currentUser = \OC::$server->getUserSession()->getUser(); | |
| 108 | + | |
| 109 | + $fileMovedOutOfSharedFolder = false; | |
| 110 | + | |
| 111 | +        try { | |
| 112 | +            if ($currentUser) { | |
| 113 | + $currentUserId = $currentUser->getUID(); | |
| 114 | + | |
| 115 | + $view = new View($currentUserId . '/files'); | |
| 116 | + $fileInfo = $view->getFileInfo($oldPath); | |
| 117 | +                if ($fileInfo) { | |
| 118 | + $sourceStorage = $fileInfo->getStorage(); | |
| 119 | + $sourceOwner = $view->getOwner($oldPath); | |
| 120 | + $targetOwner = $view->getOwner($newPath); | |
| 121 | + | |
| 122 | + if ($sourceOwner !== $targetOwner | |
| 123 | +                        && $sourceStorage->instanceOfStorage('OCA\Files_Sharing\SharedStorage') | |
| 124 | +                    ) { | |
| 125 | + $fileMovedOutOfSharedFolder = true; | |
| 126 | + } | |
| 127 | + } | |
| 128 | + } | |
| 129 | +        } catch (\Exception $e) { | |
| 130 | + // do nothing, in this case we just disable the trashbin and continue | |
| 131 | + $logger = \OC::$server->getLogger(); | |
| 132 | +            $logger->debug('Trashbin storage could not check if a file was moved out of a shared folder: ' . $e->getMessage()); | |
| 133 | + } | |
| 134 | + | |
| 135 | +        if($fileMovedOutOfSharedFolder) { | |
| 136 | + self::$moveOutOfSharedFolder['/' . $currentUserId . '/files' . $oldPath] = true; | |
| 137 | +        } else { | |
| 138 | + self::$disableTrash = true; | |
| 139 | + } | |
| 140 | + | |
| 141 | + } | |
| 142 | + | |
| 143 | + /** | |
| 144 | + * @internal | |
| 145 | + */ | |
| 146 | +    public static function postRenameHook($params) { | |
| 147 | + self::$disableTrash = false; | |
| 148 | + } | |
| 149 | + | |
| 150 | + /** | |
| 151 | + * Rename path1 to path2 by calling the wrapped storage. | |
| 152 | + * | |
| 153 | + * @param string $path1 first path | |
| 154 | + * @param string $path2 second path | |
| 155 | + * @return bool | |
| 156 | + */ | |
| 157 | +    public function rename($path1, $path2) { | |
| 158 | + $result = $this->storage->rename($path1, $path2); | |
| 159 | +        if ($result === false) { | |
| 160 | + // when rename failed, the post_rename hook isn't triggered, | |
| 161 | + // but we still want to reenable the trash logic | |
| 162 | + self::$disableTrash = false; | |
| 163 | + } | |
| 164 | + return $result; | |
| 165 | + } | |
| 166 | + | |
| 167 | + /** | |
| 168 | + * Deletes the given file by moving it into the trashbin. | |
| 169 | + * | |
| 170 | + * @param string $path path of file or folder to delete | |
| 171 | + * | |
| 172 | + * @return bool true if the operation succeeded, false otherwise | |
| 173 | + */ | |
| 174 | +    public function unlink($path) { | |
| 175 | +        try { | |
| 176 | +            if (isset(self::$moveOutOfSharedFolder[$this->mountPoint . $path])) { | |
| 177 | + $result = $this->doDelete($path, 'unlink', true); | |
| 178 | + unset(self::$moveOutOfSharedFolder[$this->mountPoint . $path]); | |
| 179 | +            } else { | |
| 180 | + $result = $this->doDelete($path, 'unlink'); | |
| 181 | + } | |
| 182 | +        } catch (GenericEncryptionException $e) { | |
| 183 | + // in case of a encryption exception we delete the file right away | |
| 184 | + $this->logger->info( | |
| 185 | + "Can't move file" . $path . | |
| 186 | + "to the trash bin, therefore it was deleted right away"); | |
| 187 | + | |
| 188 | + $result = $this->storage->unlink($path); | |
| 189 | + } | |
| 190 | + | |
| 191 | + return $result; | |
| 192 | + } | |
| 193 | + | |
| 194 | + /** | |
| 195 | + * Deletes the given folder by moving it into the trashbin. | |
| 196 | + * | |
| 197 | + * @param string $path path of folder to delete | |
| 198 | + * | |
| 199 | + * @return bool true if the operation succeeded, false otherwise | |
| 200 | + */ | |
| 201 | +    public function rmdir($path) { | |
| 202 | +        if (isset(self::$moveOutOfSharedFolder[$this->mountPoint . $path])) { | |
| 203 | + $result = $this->doDelete($path, 'rmdir', true); | |
| 204 | + unset(self::$moveOutOfSharedFolder[$this->mountPoint . $path]); | |
| 205 | +        } else { | |
| 206 | + $result = $this->doDelete($path, 'rmdir'); | |
| 207 | + } | |
| 208 | + | |
| 209 | + return $result; | |
| 210 | + } | |
| 211 | + | |
| 212 | + /** | |
| 213 | + * check if it is a file located in data/user/files only files in the | |
| 214 | + * 'files' directory should be moved to the trash | |
| 215 | + * | |
| 216 | + * @param $path | |
| 217 | + * @return bool | |
| 218 | + */ | |
| 219 | +    protected function shouldMoveToTrash($path){ | |
| 220 | + | |
| 221 | + // check if there is a app which want to disable the trash bin for this file | |
| 222 | + $fileId = $this->storage->getCache()->getId($path); | |
| 223 | + $nodes = $this->rootFolder->getById($fileId); | |
| 224 | +        foreach ($nodes as $node) { | |
| 225 | + $event = $this->createMoveToTrashEvent($node); | |
| 226 | +            $this->eventDispatcher->dispatch('OCA\Files_Trashbin::moveToTrash', $event); | |
| 227 | +            if ($event->shouldMoveToTrashBin() === false) { | |
| 228 | + return false; | |
| 229 | + } | |
| 230 | + } | |
| 231 | + | |
| 232 | + $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path); | |
| 233 | +        $parts = explode('/', $normalized); | |
| 234 | +        if (count($parts) < 4) { | |
| 235 | + return false; | |
| 236 | + } | |
| 237 | + | |
| 238 | +        if ($this->userManager->userExists($parts[1]) && $parts[2] === 'files') { | |
| 239 | + return true; | |
| 240 | + } | |
| 241 | + | |
| 242 | + return false; | |
| 243 | + } | |
| 244 | + | |
| 245 | + /** | |
| 246 | + * get move to trash event | |
| 247 | + * | |
| 248 | + * @param Node $node | |
| 249 | + * @return MoveToTrashEvent | |
| 250 | + */ | |
| 251 | +    protected function createMoveToTrashEvent(Node $node) { | |
| 252 | + $event = new MoveToTrashEvent($node); | |
| 253 | + return $event; | |
| 254 | + } | |
| 255 | + | |
| 256 | + /** | |
| 257 | + * Run the delete operation with the given method | |
| 258 | + * | |
| 259 | + * @param string $path path of file or folder to delete | |
| 260 | + * @param string $method either "unlink" or "rmdir" | |
| 261 | + * @param bool $ownerOnly delete for owner only (if file gets moved out of a shared folder) | |
| 262 | + * | |
| 263 | + * @return bool true if the operation succeeded, false otherwise | |
| 264 | + */ | |
| 265 | +    private function doDelete($path, $method, $ownerOnly = false) { | |
| 266 | + if (self::$disableTrash | |
| 267 | +            || !\OC_App::isEnabled('files_trashbin') | |
| 268 | + || (pathinfo($path, PATHINFO_EXTENSION) === 'part') | |
| 269 | + || $this->shouldMoveToTrash($path) === false | |
| 270 | +        ) { | |
| 271 | + return call_user_func_array([$this->storage, $method], [$path]); | |
| 272 | + } | |
| 273 | + | |
| 274 | + // check permissions before we continue, this is especially important for | |
| 275 | + // shared files | |
| 276 | +        if (!$this->isDeletable($path)) { | |
| 277 | + return false; | |
| 278 | + } | |
| 279 | + | |
| 280 | + $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path, true, false, true); | |
| 281 | + $result = true; | |
| 282 | + $view = Filesystem::getView(); | |
| 283 | +        if (!isset($this->deletedFiles[$normalized]) && $view instanceof View) { | |
| 284 | + $this->deletedFiles[$normalized] = $normalized; | |
| 285 | +            if ($filesPath = $view->getRelativePath($normalized)) { | |
| 286 | + $filesPath = trim($filesPath, '/'); | |
| 287 | + $result = \OCA\Files_Trashbin\Trashbin::move2trash($filesPath, $ownerOnly); | |
| 288 | + // in cross-storage cases the file will be copied | |
| 289 | + // but not deleted, so we delete it here | |
| 290 | +                if ($result) { | |
| 291 | + call_user_func_array([$this->storage, $method], [$path]); | |
| 292 | + } | |
| 293 | +            } else { | |
| 294 | + $result = call_user_func_array([$this->storage, $method], [$path]); | |
| 295 | + } | |
| 296 | + unset($this->deletedFiles[$normalized]); | |
| 297 | +        } else if ($this->storage->file_exists($path)) { | |
| 298 | + $result = call_user_func_array([$this->storage, $method], [$path]); | |
| 299 | + } | |
| 300 | + | |
| 301 | + return $result; | |
| 302 | + } | |
| 303 | + | |
| 304 | + /** | |
| 305 | + * Setup the storate wrapper callback | |
| 306 | + */ | |
| 307 | +    public static function setupStorage() { | |
| 308 | +        \OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) { | |
| 309 | + return new \OCA\Files_Trashbin\Storage( | |
| 310 | +                array('storage' => $storage, 'mountPoint' => $mountPoint), | |
| 311 | + \OC::$server->getUserManager(), | |
| 312 | + \OC::$server->getLogger(), | |
| 313 | + \OC::$server->getEventDispatcher(), | |
| 314 | + \OC::$server->getLazyRootFolder() | |
| 315 | + ); | |
| 316 | + }, 1); | |
| 317 | + } | |
| 318 | 318 | |
| 319 | 319 | } | 
| @@ -112,7 +112,7 @@ discard block | ||
| 112 | 112 |  			if ($currentUser) { | 
| 113 | 113 | $currentUserId = $currentUser->getUID(); | 
| 114 | 114 | |
| 115 | - $view = new View($currentUserId . '/files'); | |
| 115 | + $view = new View($currentUserId.'/files'); | |
| 116 | 116 | $fileInfo = $view->getFileInfo($oldPath); | 
| 117 | 117 |  				if ($fileInfo) { | 
| 118 | 118 | $sourceStorage = $fileInfo->getStorage(); | 
| @@ -129,11 +129,11 @@ discard block | ||
| 129 | 129 |  		} catch (\Exception $e) { | 
| 130 | 130 | // do nothing, in this case we just disable the trashbin and continue | 
| 131 | 131 | $logger = \OC::$server->getLogger(); | 
| 132 | -			$logger->debug('Trashbin storage could not check if a file was moved out of a shared folder: ' . $e->getMessage()); | |
| 132 | +			$logger->debug('Trashbin storage could not check if a file was moved out of a shared folder: '.$e->getMessage()); | |
| 133 | 133 | } | 
| 134 | 134 | |
| 135 | -		if($fileMovedOutOfSharedFolder) { | |
| 136 | - self::$moveOutOfSharedFolder['/' . $currentUserId . '/files' . $oldPath] = true; | |
| 135 | +		if ($fileMovedOutOfSharedFolder) { | |
| 136 | + self::$moveOutOfSharedFolder['/'.$currentUserId.'/files'.$oldPath] = true; | |
| 137 | 137 |  		} else { | 
| 138 | 138 | self::$disableTrash = true; | 
| 139 | 139 | } | 
| @@ -173,16 +173,16 @@ discard block | ||
| 173 | 173 | */ | 
| 174 | 174 |  	public function unlink($path) { | 
| 175 | 175 |  		try { | 
| 176 | -			if (isset(self::$moveOutOfSharedFolder[$this->mountPoint . $path])) { | |
| 176 | +			if (isset(self::$moveOutOfSharedFolder[$this->mountPoint.$path])) { | |
| 177 | 177 | $result = $this->doDelete($path, 'unlink', true); | 
| 178 | - unset(self::$moveOutOfSharedFolder[$this->mountPoint . $path]); | |
| 178 | + unset(self::$moveOutOfSharedFolder[$this->mountPoint.$path]); | |
| 179 | 179 |  			} else { | 
| 180 | 180 | $result = $this->doDelete($path, 'unlink'); | 
| 181 | 181 | } | 
| 182 | 182 |  		} catch (GenericEncryptionException $e) { | 
| 183 | 183 | // in case of a encryption exception we delete the file right away | 
| 184 | 184 | $this->logger->info( | 
| 185 | - "Can't move file" . $path . | |
| 185 | + "Can't move file".$path. | |
| 186 | 186 | "to the trash bin, therefore it was deleted right away"); | 
| 187 | 187 | |
| 188 | 188 | $result = $this->storage->unlink($path); | 
| @@ -199,9 +199,9 @@ discard block | ||
| 199 | 199 | * @return bool true if the operation succeeded, false otherwise | 
| 200 | 200 | */ | 
| 201 | 201 |  	public function rmdir($path) { | 
| 202 | -		if (isset(self::$moveOutOfSharedFolder[$this->mountPoint . $path])) { | |
| 202 | +		if (isset(self::$moveOutOfSharedFolder[$this->mountPoint.$path])) { | |
| 203 | 203 | $result = $this->doDelete($path, 'rmdir', true); | 
| 204 | - unset(self::$moveOutOfSharedFolder[$this->mountPoint . $path]); | |
| 204 | + unset(self::$moveOutOfSharedFolder[$this->mountPoint.$path]); | |
| 205 | 205 |  		} else { | 
| 206 | 206 | $result = $this->doDelete($path, 'rmdir'); | 
| 207 | 207 | } | 
| @@ -216,7 +216,7 @@ discard block | ||
| 216 | 216 | * @param $path | 
| 217 | 217 | * @return bool | 
| 218 | 218 | */ | 
| 219 | -	protected function shouldMoveToTrash($path){ | |
| 219 | +	protected function shouldMoveToTrash($path) { | |
| 220 | 220 | |
| 221 | 221 | // check if there is a app which want to disable the trash bin for this file | 
| 222 | 222 | $fileId = $this->storage->getCache()->getId($path); | 
| @@ -229,7 +229,7 @@ discard block | ||
| 229 | 229 | } | 
| 230 | 230 | } | 
| 231 | 231 | |
| 232 | - $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path); | |
| 232 | + $normalized = Filesystem::normalizePath($this->mountPoint.'/'.$path); | |
| 233 | 233 |  		$parts = explode('/', $normalized); | 
| 234 | 234 |  		if (count($parts) < 4) { | 
| 235 | 235 | return false; | 
| @@ -277,7 +277,7 @@ discard block | ||
| 277 | 277 | return false; | 
| 278 | 278 | } | 
| 279 | 279 | |
| 280 | - $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path, true, false, true); | |
| 280 | + $normalized = Filesystem::normalizePath($this->mountPoint.'/'.$path, true, false, true); | |
| 281 | 281 | $result = true; | 
| 282 | 282 | $view = Filesystem::getView(); | 
| 283 | 283 |  		if (!isset($this->deletedFiles[$normalized]) && $view instanceof View) { | 
| @@ -305,7 +305,7 @@ discard block | ||
| 305 | 305 | * Setup the storate wrapper callback | 
| 306 | 306 | */ | 
| 307 | 307 |  	public static function setupStorage() { | 
| 308 | -		\OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) { | |
| 308 | +		\OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function($mountPoint, $storage) { | |
| 309 | 309 | return new \OCA\Files_Trashbin\Storage( | 
| 310 | 310 |  				array('storage' => $storage, 'mountPoint' => $mountPoint), | 
| 311 | 311 | \OC::$server->getUserManager(), | 
| @@ -35,39 +35,39 @@ | ||
| 35 | 35 | */ | 
| 36 | 36 |  class MoveToTrashEvent extends Event { | 
| 37 | 37 | |
| 38 | - /** @var bool */ | |
| 39 | - private $moveToTrashBin; | |
| 38 | + /** @var bool */ | |
| 39 | + private $moveToTrashBin; | |
| 40 | 40 | |
| 41 | - /** @var Node */ | |
| 42 | - private $node; | |
| 41 | + /** @var Node */ | |
| 42 | + private $node; | |
| 43 | 43 | |
| 44 | -	public function __construct(Node $node) { | |
| 45 | - $this->moveToTrashBin = true; | |
| 46 | - $this->node = $node; | |
| 47 | - } | |
| 44 | +    public function __construct(Node $node) { | |
| 45 | + $this->moveToTrashBin = true; | |
| 46 | + $this->node = $node; | |
| 47 | + } | |
| 48 | 48 | |
| 49 | - /** | |
| 50 | - * get Node which will be deleted | |
| 51 | - * | |
| 52 | - * @return Node | |
| 53 | - */ | |
| 54 | -	public function getNode() { | |
| 55 | - return $this->node; | |
| 56 | - } | |
| 49 | + /** | |
| 50 | + * get Node which will be deleted | |
| 51 | + * | |
| 52 | + * @return Node | |
| 53 | + */ | |
| 54 | +    public function getNode() { | |
| 55 | + return $this->node; | |
| 56 | + } | |
| 57 | 57 | |
| 58 | - /** | |
| 59 | - * disable trash bin for this operation | |
| 60 | - */ | |
| 61 | -	public function disableTrashBin() { | |
| 62 | - $this->moveToTrashBin = false; | |
| 63 | - } | |
| 58 | + /** | |
| 59 | + * disable trash bin for this operation | |
| 60 | + */ | |
| 61 | +    public function disableTrashBin() { | |
| 62 | + $this->moveToTrashBin = false; | |
| 63 | + } | |
| 64 | 64 | |
| 65 | - /** | |
| 66 | - * should the file be moved to the trash bin? | |
| 67 | - * | |
| 68 | - * @return bool | |
| 69 | - */ | |
| 70 | -	public function shouldMoveToTrashBin() { | |
| 71 | - return $this->moveToTrashBin; | |
| 72 | - } | |
| 65 | + /** | |
| 66 | + * should the file be moved to the trash bin? | |
| 67 | + * | |
| 68 | + * @return bool | |
| 69 | + */ | |
| 70 | +    public function shouldMoveToTrashBin() { | |
| 71 | + return $this->moveToTrashBin; | |
| 72 | + } | |
| 73 | 73 | } |