Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Try to use the display name of file transfers
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Apr 8, 2020
commit f8a5812f9846fe9799eacd2f2231af3707016e36
26 changes: 20 additions & 6 deletions apps/files/lib/Service/OwnershipTransferService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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;
Expand Down Expand Up @@ -94,18 +95,31 @@ public function transfer(IUser $sourceUser,
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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ public static function normalizePath($path, $stripTrailingSlash = true, $isAbsol
$patterns = [
'/\\\\/s', // no windows style slashes
'/\/\.(\/\.)?\//s', // remove '/./'
'/\/{2,}/s', // remove squence of slashes
'/\/{2,}/s', // remove sequence of slashes
'/\/\.$/s', // remove trailing /.
];

Expand Down