Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
This works with dirs and files in any number of combinations.
|
||||
*/
|
||||
|
||||
function _commonPath($dirList)
|
||||
{
|
||||
$arr = array();
|
||||
foreach($dirList as $i => $path)
|
||||
{
|
||||
$dirList[$i] = explode('/', $path);
|
||||
unset($dirList[$i][0]);
|
||||
|
||||
$arr[$i] = count($dirList[$i]);
|
||||
}
|
||||
|
||||
$min = min($arr);
|
||||
|
||||
for($i = 0; $i < count($dirList); $i++)
|
||||
{
|
||||
while(count($dirList[$i]) > $min)
|
||||
{
|
||||
array_pop($dirList[$i]);
|
||||
}
|
||||
|
||||
$dirList[$i] = '/' . implode('/' , $dirList[$i]);
|
||||
}
|
||||
|
||||
$dirList = array_unique($dirList);
|
||||
while(count($dirList) !== 1)
|
||||
{
|
||||
$dirList = array_map('dirname', $dirList);
|
||||
$dirList = array_unique($dirList);
|
||||
}
|
||||
reset($dirList);
|
||||
|
||||
return current($dirList);
|
||||
}
|
||||
|
||||
/* TEST */
|
||||
|
||||
$dirs = array(
|
||||
'/home/user1/tmp/coverage/test',
|
||||
'/home/user1/tmp/covert/operator',
|
||||
'/home/user1/tmp/coven/members',
|
||||
);
|
||||
|
||||
|
||||
if('/home/user1/tmp' !== common_path($dirs))
|
||||
{
|
||||
echo 'test fail';
|
||||
} else {
|
||||
echo 'test success';
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/* A more compact string-only version, which I assume would be much faster */
|
||||
/* If you want the trailing /, return $common; */
|
||||
|
||||
function getCommonPath($paths) {
|
||||
$lastOffset = 1;
|
||||
$common = '/';
|
||||
while (($index = strpos($paths[0], '/', $lastOffset)) !== FALSE) {
|
||||
$dirLen = $index - $lastOffset + 1; // include /
|
||||
$dir = substr($paths[0], $lastOffset, $dirLen);
|
||||
foreach ($paths as $path) {
|
||||
if (substr($path, $lastOffset, $dirLen) != $dir)
|
||||
return $common;
|
||||
}
|
||||
$common .= $dir;
|
||||
$lastOffset = $index + 1;
|
||||
}
|
||||
return substr($common, 0, -1);
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue