Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions src/ZipArchiveAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,34 @@ public function rename($path, $newpath)
{
$source = $this->applyPathPrefix($path);
$destination = $this->applyPathPrefix($newpath);
$info = $this->archive->statName($source);

return $this->archive->renameName($source, $destination);
if ($info && substr($info['name'], -1) !== '/') {

return $this->archive->renameName($source, $destination);

}

$source = Util::normalizePrefix($source, '/');
$destination = Util::normalizePrefix($destination, '/');
$length = strlen($source);
$result = true;

// This is needed to ensure the right number of
// files are set to the $numFiles property.
$this->reopenArchive();

for ($i = 0; $i < $this->archive->numFiles; $i++) {
$info = $this->archive->statIndex($i);

if (substr($info['name'], 0, $length) === $source) {
if (! $result = $this->archive->renameIndex($i, $destination . substr($info['name'], $length))) {
break;
}
}
}

return $result;
}

/**
Expand Down Expand Up @@ -159,12 +185,12 @@ public function deleteDir($dirname)
for ($i = 0; $i < $this->archive->numFiles; $i++) {
$info = $this->archive->statIndex($i);

if (substr($info['name'], 0, $length) === $path) {
if (substr($info['name'], 0, $length) === $path && $info['name'] !== $path) {
$this->archive->deleteIndex($i);
}
}

return $this->archive->deleteName($dirname);
return $this->archive->deleteName($path);
}

/**
Expand Down