From df9b509ed33ef6e3041b76b4b7ce1b22c7d81fcc Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 17 Aug 2016 09:58:53 +0200 Subject: Improve regexp to detect duplicate folders when repairing unmerged shares --- lib/private/Repair/RepairUnmergedShares.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'lib/private/Repair') diff --git a/lib/private/Repair/RepairUnmergedShares.php b/lib/private/Repair/RepairUnmergedShares.php index c29de87c4e8..d57bc3779f8 100644 --- a/lib/private/Repair/RepairUnmergedShares.php +++ b/lib/private/Repair/RepairUnmergedShares.php @@ -148,6 +148,10 @@ class RepairUnmergedShares implements IRepairStep { return $groupedShares; } + private function isPotentialDuplicateName($name) { + return (preg_match('/\(\d+\)(\.[^\.]+)?$/', $name) === 1); + } + /** * 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 @@ -169,18 +173,12 @@ class RepairUnmergedShares implements IRepairStep { $pickedShare = null; // sort by stime, this also properly sorts the direct user share if any @usort($subShares, function($a, $b) { - if ($a['stime'] < $b['stime']) { - return -1; - } else if ($a['stime'] > $b['stime']) { - return 1; - } - - return 0; + return ((int)$a['stime'] - (int)$b['stime']); }); foreach ($subShares as $subShare) { // skip entries that have parenthesis with numbers - if (preg_match('/\([0-9]*\)/', $subShare['file_target']) === 1) { + if ($this->isPotentialDuplicateName($subShare['file_target'])) { continue; } // pick any share found that would match, the last being the most recent -- cgit v1.2.3