diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-04-08 19:36:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-08 19:36:59 +0200 |
commit | 328fbddc197d7e51a466467c6ba788c5b972811d (patch) | |
tree | 8d8cb22bd79eda27b929215fb67964a45bc620a0 /apps/files/lib/Service/OwnershipTransferService.php | |
parent | 37146c9b0f7450cb57d4e60fc05ed56faf0c761c (diff) | |
parent | 3ea37d0d10a855438307cb69f5f9c7c452ceba95 (diff) | |
download | nextcloud-server-328fbddc197d7e51a466467c6ba788c5b972811d.tar.gz nextcloud-server-328fbddc197d7e51a466467c6ba788c5b972811d.zip |
Merge pull request #20360 from nextcloud/bugfix/20182/try-to-use-the-displayname-for-file-transfers
Try to use the display name of file transfers
Diffstat (limited to 'apps/files/lib/Service/OwnershipTransferService.php')
-rw-r--r-- | apps/files/lib/Service/OwnershipTransferService.php | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/apps/files/lib/Service/OwnershipTransferService.php b/apps/files/lib/Service/OwnershipTransferService.php index e1b26c6449e..3415a2fd9e7 100644 --- a/apps/files/lib/Service/OwnershipTransferService.php +++ b/apps/files/lib/Service/OwnershipTransferService.php @@ -36,6 +36,7 @@ use OCA\Files\Exception\TransferOwnershipException; use OCP\Encryption\IManager as IEncryptionManager; use OCP\Files\FileInfo; use OCP\Files\IHomeStorage; +use OCP\Files\InvalidPathException; use OCP\Files\Mount\IMountManager; use OCP\IUser; use OCP\Share\IManager as IShareManager; @@ -94,18 +95,31 @@ class OwnershipTransferService { throw new TransferOwnershipException("The target user is not ready to accept files. The user has at least to have logged in once.", 2); } + // setup filesystem + Filesystem::initMountPoints($sourceUid); + Filesystem::initMountPoints($destinationUid); + + $view = new View(); + if ($move) { $finalTarget = "$destinationUid/files/"; } else { $date = date('Y-m-d H-i-s'); - $finalTarget = "$destinationUid/files/transferred from $sourceUid on $date"; - } - // setup filesystem - Filesystem::initMountPoints($sourceUid); - Filesystem::initMountPoints($destinationUid); + // Remove some characters which are prone to cause errors + $cleanUserName = str_replace(['\\', '/', ':', '.', '?', '#', '\'', '"'], '-', $sourceUser->getDisplayName()); + // Replace multiple dashes with one dash + $cleanUserName = preg_replace('/-{2,}/s', '-', $cleanUserName); + $cleanUserName = $cleanUserName ?: $sourceUid; + + $finalTarget = "$destinationUid/files/transferred from $cleanUserName on $date"; + try { + $view->verifyPath(dirname($finalTarget), basename($finalTarget)); + } catch (InvalidPathException $e) { + $finalTarget = "$destinationUid/files/transferred from $sourceUid on $date"; + } + } - $view = new View(); if (!($view->is_dir($sourcePath) || $view->is_file($sourcePath))) { throw new TransferOwnershipException("Unknown path provided: $path", 1); } |