Try to use the display name of file transfers
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
981278a666
commit
f8a5812f98
|
@ -36,6 +36,7 @@ use OCA\Files\Exception\TransferOwnershipException;
|
||||||
use OCP\Encryption\IManager as IEncryptionManager;
|
use OCP\Encryption\IManager as IEncryptionManager;
|
||||||
use OCP\Files\FileInfo;
|
use OCP\Files\FileInfo;
|
||||||
use OCP\Files\IHomeStorage;
|
use OCP\Files\IHomeStorage;
|
||||||
|
use OCP\Files\InvalidPathException;
|
||||||
use OCP\Files\Mount\IMountManager;
|
use OCP\Files\Mount\IMountManager;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\Share\IManager as IShareManager;
|
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);
|
throw new TransferOwnershipException("The target user is not ready to accept files. The user has at least to have logged in once.", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($move) {
|
|
||||||
$finalTarget = "$destinationUid/files/";
|
|
||||||
} else {
|
|
||||||
$date = date('Y-m-d H-i-s');
|
|
||||||
$finalTarget = "$destinationUid/files/transferred from $sourceUid on $date";
|
|
||||||
}
|
|
||||||
|
|
||||||
// setup filesystem
|
// setup filesystem
|
||||||
Filesystem::initMountPoints($sourceUid);
|
Filesystem::initMountPoints($sourceUid);
|
||||||
Filesystem::initMountPoints($destinationUid);
|
Filesystem::initMountPoints($destinationUid);
|
||||||
|
|
||||||
$view = new View();
|
$view = new View();
|
||||||
|
|
||||||
|
if ($move) {
|
||||||
|
$finalTarget = "$destinationUid/files/";
|
||||||
|
} else {
|
||||||
|
$date = date('Y-m-d H-i-s');
|
||||||
|
|
||||||
|
// 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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!($view->is_dir($sourcePath) || $view->is_file($sourcePath))) {
|
if (!($view->is_dir($sourcePath) || $view->is_file($sourcePath))) {
|
||||||
throw new TransferOwnershipException("Unknown path provided: $path", 1);
|
throw new TransferOwnershipException("Unknown path provided: $path", 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -828,7 +828,7 @@ class Filesystem {
|
||||||
$patterns = [
|
$patterns = [
|
||||||
'/\\\\/s', // no windows style slashes
|
'/\\\\/s', // no windows style slashes
|
||||||
'/\/\.(\/\.)?\//s', // remove '/./'
|
'/\/\.(\/\.)?\//s', // remove '/./'
|
||||||
'/\/{2,}/s', // remove squence of slashes
|
'/\/{2,}/s', // remove sequence of slashes
|
||||||
'/\/\.$/s', // remove trailing /.
|
'/\/\.$/s', // remove trailing /.
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue