Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to use the display name of file transfers #20360

Merged
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
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