Use strpos instead of strstr

Instead of just finding our dirname within the finalArray using strstr,
now using strpos and detecting if it's pos 0, which is much more
appropriate & reliable.
Example: Looking for /bob/t1.txt for may potentially return a false
positive for finding '/bob' in '/another/bob1/abc' and files therefore
t1.txt ends up in the wrong folder. This false positive only occurs when
the write order of hard drive storage has stored another/bob1/abc before
/bob and therefore retrieval load order can cause this odd, occasional
issue.
Checking for /bob being the start of our finalArray item through
strpos===0 eliminates this possibility.
This commit is contained in:
Matt Pass
2012-09-16 10:24:02 +01:00
parent b1ca05fec3
commit 4027ecee5a

View File

@@ -66,7 +66,7 @@ for ($i=0;$i<count($tempArray);$i++) {
for ($j=$insertAt;$j<count($finalArray);$j++) {
if ( strcasecmp(dirname($finalArray[$j]), dirname($tempArray[$i]))==0 &&
strcasecmp(basename($finalArray[$j]), basename($tempArray[$i]))<0 ||
strstr(dirname($finalArray[$j]),dirname($tempArray[$i]))) {
strpos(dirname($finalArray[$j]),dirname($tempArray[$i]))===0) {
$insertAt++;
}
}