visualfail: remove common path prefix from file names
Change-Id: I5806f0e4ca3ebe4e9aae3423e04d8ffb36fff2a6
This commit is contained in:
@ -140,6 +140,35 @@ function getVariants()
|
|||||||
echo json_encode($variants);
|
echo json_encode($variants);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function remove_common_prefix($files)
|
||||||
|
{
|
||||||
|
if (count($files) == 0) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
// start with arbitrary file
|
||||||
|
$commonprefix = dirname(current($files));
|
||||||
|
|
||||||
|
foreach ($files AS $id => $file) {
|
||||||
|
for ($i = 0; $i < strlen($commonprefix); ++$i) {
|
||||||
|
if ($i >= strlen($file) || $file[$i] != $commonprefix[$i]) {
|
||||||
|
$commonprefix = substr($commonprefix, 0, $i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (strlen($commonprefix) == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$out = array();
|
||||||
|
foreach ($files AS $id => $file) {
|
||||||
|
$out[$id] = substr($file, strlen($commonprefix));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
function getSourceFiles()
|
function getSourceFiles()
|
||||||
{
|
{
|
||||||
$sourceFiles = array();
|
$sourceFiles = array();
|
||||||
@ -152,6 +181,8 @@ function getSourceFiles()
|
|||||||
$sourceFiles[$row->file_id] = $row->path;
|
$sourceFiles[$row->file_id] = $row->path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sourceFiles = remove_common_prefix($sourceFiles);
|
||||||
|
|
||||||
echo json_encode($sourceFiles);
|
echo json_encode($sourceFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user