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

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-08-12 12:44:34 +0300
committerVincent Petry <pvince81@owncloud.com>2016-08-16 12:08:02 +0300
commit03a65e5e3a1100d8cbe0a8221c5d127cec30ca4a (patch)
tree495259f97cb7158237d1ed7ad3ac5941ab879cef /lib
parentc492277cf1c27c9585fbed949d6922714538f94e (diff)
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')
-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;