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 <roeland@famdouma.nl>2020-04-03 17:30:04 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2020-04-03 17:30:04 +0300
commit3c4c88721a106d10b31de384a4e6b820d2ba5f03 (patch)
treeec5f67ca5643e24713d8cb681ee7c398d16cf621
parentb8958c4de59a9822eeeb6efddbf3f23f5b81f7a0 (diff)
Make sure that the target we try to restore to doesn't exist yet
Else it may overwrite this Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
-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 3c01ea8b..eff7c5b2 100644
--- a/lib/Trash/TrashBackend.php
+++ b/lib/Trash/TrashBackend.php
@@ -111,6 +111,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);