mirror of
https://github.com/Ne-Lexa/php-zip.git
synced 2025-07-31 04:30:13 +02:00
Fix bug add files from directory iterator.
This commit is contained in:
18
.travis.yml
18
.travis.yml
@@ -7,13 +7,27 @@ php:
|
|||||||
- hhvm
|
- hhvm
|
||||||
- nightly
|
- nightly
|
||||||
|
|
||||||
|
# cache vendor dirs
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- vendor
|
||||||
|
- $HOME/.composer/cache
|
||||||
|
|
||||||
addons:
|
addons:
|
||||||
code_climate:
|
code_climate:
|
||||||
repo_token: 486a09d58d663450146c53c81c6c64938bcf3bb0b7c8ddebdc125fe97c18213a
|
repo_token: 486a09d58d663450146c53c81c6c64938bcf3bb0b7c8ddebdc125fe97c18213a
|
||||||
|
|
||||||
|
install:
|
||||||
|
- travis_retry composer self-update && composer --version
|
||||||
|
- travis_retry composer install --prefer-dist --no-interaction
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- sudo apt-get install p7zip-full
|
- sudo apt-get install p7zip-full
|
||||||
- composer install
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
vendor/bin/phpunit -v -c bootstrap.xml
|
- composer validate --no-check-lock
|
||||||
|
- vendor/bin/phpunit -v -c bootstrap.xml --coverage-clover build/logs/clover.xml
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- vendor/bin/test-reporter
|
||||||
|
|
||||||
|
@@ -11,7 +11,8 @@
|
|||||||
"zipalign"
|
"zipalign"
|
||||||
],
|
],
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "4.8"
|
"phpunit/phpunit": "4.8",
|
||||||
|
"codeclimate/php-test-reporter": "^0.4.4"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
|
@@ -296,7 +296,7 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
|||||||
* @param string $destination Location where to extract the files.
|
* @param string $destination Location where to extract the files.
|
||||||
* @param array|string|null $entries The entries to extract. It accepts either
|
* @param array|string|null $entries The entries to extract. It accepts either
|
||||||
* a single entry name or an array of names.
|
* a single entry name or an array of names.
|
||||||
* @return bool
|
* @return ZipFile
|
||||||
* @throws ZipException
|
* @throws ZipException
|
||||||
*/
|
*/
|
||||||
public function extractTo($destination, $entries = null)
|
public function extractTo($destination, $entries = null)
|
||||||
@@ -335,7 +335,6 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
|||||||
$zipEntries = $this->centralDirectory->getEntries();
|
$zipEntries = $this->centralDirectory->getEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
$extract = 0;
|
|
||||||
foreach ($zipEntries as $entry) {
|
foreach ($zipEntries as $entry) {
|
||||||
$file = $destination . DIRECTORY_SEPARATOR . $entry->getName();
|
$file = $destination . DIRECTORY_SEPARATOR . $entry->getName();
|
||||||
if ($entry->isDirectory()) {
|
if ($entry->isDirectory()) {
|
||||||
@@ -357,12 +356,11 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
|||||||
touch($dir, $entry->getTime());
|
touch($dir, $entry->getTime());
|
||||||
}
|
}
|
||||||
if (file_put_contents($file, $entry->getEntryContent()) === false) {
|
if (file_put_contents($file, $entry->getEntryContent()) === false) {
|
||||||
return false;
|
throw new ZipException('Can not extract file '.$entry->getName());
|
||||||
}
|
}
|
||||||
touch($file, $entry->getTime());
|
touch($file, $entry->getTime());
|
||||||
$extract++;
|
|
||||||
}
|
}
|
||||||
return $extract > 0;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -652,7 +650,6 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
|||||||
$files = [];
|
$files = [];
|
||||||
foreach ($iterator as $file) {
|
foreach ($iterator as $file) {
|
||||||
if ($file instanceof \SplFileInfo) {
|
if ($file instanceof \SplFileInfo) {
|
||||||
empty($path) and $path = rtrim($file->getPath(), '/');
|
|
||||||
if ('..' === $file->getBasename()) {
|
if ('..' === $file->getBasename()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -663,7 +660,12 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(empty($files)){
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
natcasesort($files);
|
||||||
|
$path = array_shift($files);
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
$relativePath = str_replace($path, $localPath, $file);
|
$relativePath = str_replace($path, $localPath, $file);
|
||||||
$relativePath = ltrim($relativePath, '/');
|
$relativePath = ltrim($relativePath, '/');
|
||||||
@@ -905,7 +907,7 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
|||||||
* Delete entries by glob pattern.
|
* Delete entries by glob pattern.
|
||||||
*
|
*
|
||||||
* @param string $globPattern Glob pattern
|
* @param string $globPattern Glob pattern
|
||||||
* @return bool
|
* @return ZipFile
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
* @sse https://en.wikipedia.org/wiki/Glob_(programming) Glob pattern syntax
|
* @sse https://en.wikipedia.org/wiki/Glob_(programming) Glob pattern syntax
|
||||||
*/
|
*/
|
||||||
@@ -915,14 +917,15 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
|||||||
throw new InvalidArgumentException("Glob pattern is empty");
|
throw new InvalidArgumentException("Glob pattern is empty");
|
||||||
}
|
}
|
||||||
$globPattern = '~' . FilesUtil::convertGlobToRegEx($globPattern) . '~si';
|
$globPattern = '~' . FilesUtil::convertGlobToRegEx($globPattern) . '~si';
|
||||||
return $this->deleteFromRegex($globPattern);
|
$this->deleteFromRegex($globPattern);
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete entries by regex pattern.
|
* Delete entries by regex pattern.
|
||||||
*
|
*
|
||||||
* @param string $regexPattern Regex pattern
|
* @param string $regexPattern Regex pattern
|
||||||
* @return bool
|
* @return ZipFile
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function deleteFromRegex($regexPattern)
|
public function deleteFromRegex($regexPattern)
|
||||||
@@ -930,7 +933,8 @@ class ZipFile implements \Countable, \ArrayAccess, \Iterator
|
|||||||
if ($regexPattern === null || !is_string($regexPattern) || empty($regexPattern)) {
|
if ($regexPattern === null || !is_string($regexPattern) || empty($regexPattern)) {
|
||||||
throw new InvalidArgumentException("Regex pattern is empty.");
|
throw new InvalidArgumentException("Regex pattern is empty.");
|
||||||
}
|
}
|
||||||
return $this->centralDirectory->deleteEntriesFromRegex($regexPattern);
|
$this->centralDirectory->deleteEntriesFromRegex($regexPattern);
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user