diff options
author | Joas Schilling <coding@schilljs.com> | 2020-04-08 15:41:20 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2020-04-08 17:38:14 +0000 |
commit | ed4927a266ffc337e25cd6686cabf7fa3cec7e5b (patch) | |
tree | 71bbcb1ab33e79601587cc33953452531f4a1635 /apps/files | |
parent | e2b96a150fa09d677fd7727bb75e358879fc0824 (diff) | |
download | nextcloud-server-ed4927a266ffc337e25cd6686cabf7fa3cec7e5b.tar.gz nextcloud-server-ed4927a266ffc337e25cd6686cabf7fa3cec7e5b.zip |
Try to use the display name of file transfers
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/files')
-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 f316216814f..34506760927 100644 --- a/apps/files/lib/Service/OwnershipTransferService.php +++ b/apps/files/lib/Service/OwnershipTransferService.php @@ -34,6 +34,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; @@ -92,18 +93,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); } |