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

Commit 5ea81c5

Browse files
committed
Fix zip operation when child drivers are remote (inc. smb) - Fix #1287
Fix base detection for archive
1 parent 61e90bc commit 5ea81c5

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

core/src/core/src/pydio/Core/Utils/Vars/PathUtils.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,43 @@ public static function unPatchPathForBaseDir($dirPath)
7373
return str_replace("__ZIP_EXTENSION__", ".zip", $dirPath);
7474
}
7575

76+
/**
77+
* Return highest common folder
78+
* @param $items
79+
* @return mixed
80+
*/
81+
public static function commonPath($items)
82+
{
83+
$arr = array();
84+
foreach($items as $i => $path)
85+
{
86+
$items[$i] = explode('/', $path);
87+
unset($items[$i][0]);
88+
89+
$arr[$i] = count($items[$i]);
90+
}
91+
92+
$min = min($arr);
93+
94+
for($i = 0; $i < count($items); $i++)
95+
{
96+
while(count($items[$i]) > $min)
97+
{
98+
array_pop($items[$i]);
99+
}
100+
101+
$items[$i] = '/' . implode('/' , $items[$i]);
102+
}
103+
104+
$items = array_unique($items);
105+
while(count($items) !== 1)
106+
{
107+
$items = array_map('dirname', $items);
108+
$items = array_unique($items);
109+
}
110+
reset($items);
111+
112+
return current($items);
113+
}
76114

77115
}

core/src/plugins/access.fs/FsAccessDriver.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,8 @@ public function downloadAction(ServerRequestInterface &$request, ResponseInterfa
650650
} else {
651651
if(isset($httpVars["dir"])){
652652
$dir = InputFilter::decodeSecureMagic($httpVars["dir"], InputFilter::SANITIZE_DIRNAME);
653+
}else{
654+
$dir = $selection->commonDirFromSelection();
653655
}
654656
$base = basename(PathUtils::forwardSlashDirname($selection->getUniqueFile()));
655657
$zip = true;
@@ -2391,7 +2393,8 @@ public function makeZip (UserSelection $selection, $dest, $basedir, $taskId = nu
23912393
$filePaths = [];
23922394
$selectedNodes = $selection->buildNodes();
23932395
foreach ($selectedNodes as $node) {
2394-
$realFile = $node->getRealFile();
2396+
//$realFile = $node->getRealFile();
2397+
$realFile = MetaStreamWrapper::getRealFSReference($node->getUrl());
23952398
if (basename($node->getPath()) == "") {
23962399
$filePaths[] = [PCLZIP_ATT_FILE_NAME => $realFile];
23972400
} else {
@@ -2427,7 +2430,7 @@ public function makeZip (UserSelection $selection, $dest, $basedir, $taskId = nu
24272430
if($basedir == "__AJXP_ZIP_FLAT__/"){
24282431
$vList = $archive->create($filePaths, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_ADD_TEMP_FILE_ON, PCLZIP_CB_PRE_ADD, $preAddCallback);
24292432
}else{
2430-
$basedir = MetaStreamWrapper::getRealFSReference($selection->currentBaseUrl()).trim($basedir);
2433+
$basedir = rtrim(MetaStreamWrapper::getRealFSReference($selection->currentBaseUrl()), '/').trim($basedir);
24312434
$this->logDebug("Basedir", [$basedir]);
24322435
$vList = $archive->create($filePaths, PCLZIP_OPT_REMOVE_PATH, $basedir, PCLZIP_OPT_NO_COMPRESSION, PCLZIP_OPT_ADD_TEMP_FILE_ON, PCLZIP_CB_PRE_ADD, $preAddCallback);
24332436
}

core/src/plugins/core.access/src/Model/UserSelection.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,15 @@ public function buildNodes()
330330

331331
}
332332

333+
/**
334+
* Find common base path for current selection
335+
* @return mixed
336+
*/
337+
public function commonDirFromSelection(){
338+
$items = array_values($this->files);
339+
return PathUtils::commonPath($items);
340+
}
341+
333342
/**
334343
* @return string
335344
* @throws \Exception

0 commit comments

Comments
 (0)