Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix zip operation when child drivers are remote (inc. smb) - Fix #1287
Browse files Browse the repository at this point in the history
Fix base detection for archive
  • Loading branch information
cdujeu committed Nov 19, 2016
1 parent 61e90bc commit 5ea81c5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
38 changes: 38 additions & 0 deletions core/src/core/src/pydio/Core/Utils/Vars/PathUtils.php
Expand Up @@ -73,5 +73,43 @@ public static function unPatchPathForBaseDir($dirPath)
return str_replace("__ZIP_EXTENSION__", ".zip", $dirPath);
}

/**
* Return highest common folder
* @param $items
* @return mixed
*/
public static function commonPath($items)
{
$arr = array();
foreach($items as $i => $path)
{
$items[$i] = explode('/', $path);
unset($items[$i][0]);

$arr[$i] = count($items[$i]);
}

$min = min($arr);

for($i = 0; $i < count($items); $i++)
{
while(count($items[$i]) > $min)
{
array_pop($items[$i]);
}

$items[$i] = '/' . implode('/' , $items[$i]);
}

$items = array_unique($items);
while(count($items) !== 1)
{
$items = array_map('dirname', $items);
$items = array_unique($items);
}
reset($items);

return current($items);
}

}
7 changes: 5 additions & 2 deletions core/src/plugins/access.fs/FsAccessDriver.php
Expand Up @@ -650,6 +650,8 @@ public function downloadAction(ServerRequestInterface &$request, ResponseInterfa
} else {
if(isset($httpVars["dir"])){
$dir = InputFilter::decodeSecureMagic($httpVars["dir"], InputFilter::SANITIZE_DIRNAME);
}else{
$dir = $selection->commonDirFromSelection();
}
$base = basename(PathUtils::forwardSlashDirname($selection->getUniqueFile()));
$zip = true;
Expand Down Expand Up @@ -2391,7 +2393,8 @@ public function makeZip (UserSelection $selection, $dest, $basedir, $taskId = nu
$filePaths = [];
$selectedNodes = $selection->buildNodes();
foreach ($selectedNodes as $node) {
$realFile = $node->getRealFile();
//$realFile = $node->getRealFile();
$realFile = MetaStreamWrapper::getRealFSReference($node->getUrl());
if (basename($node->getPath()) == "") {
$filePaths[] = [PCLZIP_ATT_FILE_NAME => $realFile];
} else {
Expand Down Expand Up @@ -2427,7 +2430,7 @@ public function makeZip (UserSelection $selection, $dest, $basedir, $taskId = nu
if($basedir == "__AJXP_ZIP_FLAT__/"){
$vList = $archive->create($filePaths, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_ADD_TEMP_FILE_ON, PCLZIP_CB_PRE_ADD, $preAddCallback);
}else{
$basedir = MetaStreamWrapper::getRealFSReference($selection->currentBaseUrl()).trim($basedir);
$basedir = rtrim(MetaStreamWrapper::getRealFSReference($selection->currentBaseUrl()), '/').trim($basedir);
$this->logDebug("Basedir", [$basedir]);
$vList = $archive->create($filePaths, PCLZIP_OPT_REMOVE_PATH, $basedir, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_ADD_TEMP_FILE_ON, PCLZIP_CB_PRE_ADD, $preAddCallback);
}
Expand Down
9 changes: 9 additions & 0 deletions core/src/plugins/core.access/src/Model/UserSelection.php
Expand Up @@ -330,6 +330,15 @@ public function buildNodes()

}

/**
* Find common base path for current selection
* @return mixed
*/
public function commonDirFromSelection(){
$items = array_values($this->files);
return PathUtils::commonPath($items);
}

/**
* @return string
* @throws \Exception
Expand Down

0 comments on commit 5ea81c5

Please sign in to comment.