Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/groupfolders.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-04-06 10:07:18 +0300
committerGitHub <noreply@github.com>2020-04-06 10:07:18 +0300
commit5e54e47ddc0e10508fb0cd5de38337df77308aa4 (patch)
treec13e0dfa9ff6f12c712e060a2f4961ce96afdc68
parent395aac27285e8c56387444eccbac57191a7e0778 (diff)
parent3c4c88721a106d10b31de384a4e6b820d2ba5f03 (diff)
Merge pull request #842 from nextcloud/fix/trash_restore_target
Make sure that the target we try to restore to doesn't exist yet
-rw-r--r--lib/Trash/TrashBackend.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/Trash/TrashBackend.php b/lib/Trash/TrashBackend.php
index dd57384b..94933d3c 100644
--- a/lib/Trash/TrashBackend.php
+++ b/lib/Trash/TrashBackend.php
@@ -115,6 +115,33 @@ class TrashBackend implements ITrashBackend {
if ($parent !== '' && !$targetFolder->nodeExists($parent)) {
$originalLocation = basename($originalLocation);
}
+
+ if ($targetFolder->nodeExists($originalLocation)) {
+ $info = pathinfo($originalLocation);
+ $i = 1;
+
+ $gen = function($info, $i): string {
+ $target = $info['dirname'];
+ if ($target === '.') {
+ $target = '';
+ }
+
+ $target .= $info['filename'];
+ $target .= ' (' . $i . ')';
+
+ if (isset($info['extension'])) {
+ $target .= $info['extension'];
+ }
+
+ return $target;
+ };
+
+ do {
+ $originalLocation = $gen($info, $i);
+ $i++;
+ } while($targetFolder->nodeExists($originalLocation));
+ }
+
$targetLocation = $targetFolder->getInternalPath() . '/' . $originalLocation;
$targetFolder->getStorage()->moveFromStorage($trashStorage, $node->getInternalPath(), $targetLocation);
$targetFolder->getStorage()->getCache()->moveFromCache($trashStorage->getCache(), $node->getInternalPath(), $targetLocation);