aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Repair
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-08-12 11:44:34 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2016-08-17 15:31:35 +0200
commit56b94b220da4d947438ffee7a4e889ef7f61bbde (patch)
tree1f8a9cfd3fc2fb3f7979af23a01dd56e3b04eb8c /lib/private/Repair
parent39c180117ea48c313de09223eec111d14188588d (diff)
downloadnextcloud-server-56b94b220da4d947438ffee7a4e889ef7f61bbde.tar.gz
nextcloud-server-56b94b220da4d947438ffee7a4e889ef7f61bbde.zip
Improve file_target finding logic when repairing unmerged shares
Pick the most recent subshare that has no parenthesis from duplication which should match whichever name the user picked last. If all subshares have duplicate parenthesis names, use the least recent group share's target instead.
Diffstat (limited to 'lib/private/Repair')
-rw-r--r--lib/private/Repair/RepairUnmergedShares.php40
1 files changed, 39 insertions, 1 deletions
diff --git a/lib/private/Repair/RepairUnmergedShares.php b/lib/private/Repair/RepairUnmergedShares.php
index 353877bb873..f14e98c1761 100644
--- a/lib/private/Repair/RepairUnmergedShares.php
+++ b/lib/private/Repair/RepairUnmergedShares.php
@@ -149,6 +149,44 @@ class RepairUnmergedShares implements IRepairStep {
}
/**
+ * Decide on the best target name based on all group shares and subshares,
+ * goal is to increase the likeliness that the chosen name matches what
+ * the user is expecting.
+ *
+ * For this, we discard the entries with parenthesis "(2)".
+ * In case the user also renamed the duplicates to a legitimate name, this logic
+ * will still pick the most recent one as it's the one the user is most likely to
+ * remember renaming.
+ *
+ * If no suitable subshare is found, use the least recent group share instead.
+ *
+ * @param array $groupShares group share entries
+ * @param array $subShares sub share entries, sorted by stime
+ *
+ * @return string chosen target name
+ */
+ private function findBestTargetName($groupShares, $subShares) {
+ $pickedShare = null;
+ // note subShares are sorted by stime from oldest to newest
+ foreach ($subShares as $subShare) {
+ // skip entries that have parenthesis with numbers
+ if (preg_match('/\([0-9]*\)/', $subShare['file_target']) === 1) {
+ continue;
+ }
+ // pick any share found that would match, the last being the most recent
+ $pickedShare = $subShare;
+ }
+
+ // no suitable subshare found
+ if ($pickedShare === null) {
+ // use least recent group share target instead
+ $pickedShare = $groupShares[0];
+ }
+
+ return $pickedShare['file_target'];
+ }
+
+ /**
* Fix the given received share represented by the set of group shares
* and matching sub shares
*
@@ -171,7 +209,7 @@ class RepairUnmergedShares implements IRepairStep {
return false;
}
- $targetPath = $groupShares[0]['file_target'];
+ $targetPath = $this->findBestTargetName($groupShares, $subShares);
// check whether the user opted out completely of all subshares
$optedOut = true;