Commit 30e059d3 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Extract zip files into the correct folder when there is no explicit zip entry...


Extract zip files into the correct folder when there is no explicit zip entry for every folder (bug #520169)
Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 5b216e36
......@@ -1708,6 +1708,29 @@ class ArtefactTypeArchive extends ArtefactTypeFile {
$this->info = $zipinfo;
}
private function read_entry($name, $isfolder, $size) {
$path = split('/', $name);
if ($isfolder) {
array_pop($path);
}
$folder = '';
for ($i = 0; $i < count($path) - 1; $i++) {
$folder .= $path[$i] . '/';
if (!isset($this->foldernames[$folder])) {
$this->foldernames[$folder] = 1;
$this->info->names[] = $folder;
$this->info->folders++;
}
}
if (!$isfolder) {
$this->info->names[] = $name;
$this->info->files++;
$this->info->totalsize += $size;
}
}
public function read_archive() {
if (!$this->handle) {
$this->open_archive();
......@@ -1721,49 +1744,26 @@ class ArtefactTypeArchive extends ArtefactTypeFile {
'totalsize' => 0,
'names' => array(),
);
$this->foldernames = array();
if ($this->archivetype == 'zip') {
while ($entry = zip_read($this->handle)) {
$name = zip_entry_name($entry);
$this->info->names[] = $name;
if (substr($name, -1) == '/') {
$this->info->folders++;
}
else {
$this->info->files++;
if ($size = zip_entry_filesize($entry)) {
$this->info->totalsize += $size;
}
}
$isfolder = substr($name, -1) == '/';
$size = $isfolder ? 0 : zip_entry_filesize($entry);
$this->read_entry($name, $isfolder, $size);
}
}
else if ($this->archivetype == 'tar') {
$foldernames = array();
$list = $this->handle->listContent();
if (empty($list)) {
throw new SystemException("Unknown archive type");
}
foreach ($list as $entry) {
$path = split('/', $entry['filename']);
if ($isfolder = substr($entry['filename'], -1) == '/') {
array_pop($path);
}
$folder = '';
for ($i = 0; $i < count($path) - 1; $i++) {
$folder .= $path[$i] . '/';
if (!isset($foldernames[$folder])) {
$foldernames[$folder] = 1;
$this->info->names[] = $folder;
$this->info->folders++;
}
}
if (!$isfolder) {
$this->info->names[] = $entry['filename'];
$this->info->files++;
$this->info->totalsize += $entry['size'];
}
$isfolder = substr($entry['filename'], -1) == '/';
$size = $isfolder ? 0 : $entry['size'];
$this->read_entry($entry['filename'], $isfolder, $size);
}
}
else {
......@@ -1872,6 +1872,23 @@ class ArtefactTypeArchive extends ArtefactTypeFile {
while ($entry = zip_read($this->handle)) {
$name = zip_entry_name($entry);
$folder = dirname($name);
// Create parent folders if necessary
if (!isset($this->data['folderids'][$folder])) {
$parent = '.';
$child = '';
$path = split('/', $folder);
for ($i = 0; $i < count($path); $i++) {
$child .= $path[$i] . '/';
if (!isset($this->data['folderids'][$child])) {
$this->data['template']->parent = $this->data['folderids'][$parent];
$this->data['template']->title = $path[$i];
$this->create_folder($parent);
}
$parent = $child;
}
}
$this->data['template']->parent = $this->data['folderids'][$folder];
$this->data['template']->title = basename($name);
if (substr($name, -1) == '/') {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment