Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix rename directory and result of deleteDir() #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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