Skip to content

Commit

Permalink
clean up if extraction fails
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed Nov 21, 2024
1 parent d46a1cc commit a05a159
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
21 changes: 13 additions & 8 deletions src/Bzip.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,22 @@ public function extract($pathExtracted)
}

$output = fopen($pathExtracted, 'w');
while (!feof($file)) {
$content = fread($file, 1024 * 1024);

if (false === $content) {
$this->error = "fread failed";
return false;
try {
while (!feof($file)) {
$content = fread($file, 1024 * 1024);

if (false === $content) {
$this->error = "fread failed";
@unlink($pathExtracted);
return false;
}

fwrite($output, $content);
}
fwrite($output, $content);
} finally {
fclose($output);
}
fclose($output);

$success = bzclose($file);
if (false === $success) {
Expand Down
21 changes: 13 additions & 8 deletions src/Gzip.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,22 @@ public function extract($pathExtracted)
}

$output = fopen($pathExtracted, 'w');
while (!feof($file)) {
$content = fread($file, 1024 * 1024);

if (false === $content) {
$this->error = "fread failed";
return false;
}
try {
while (!feof($file)) {
$content = fread($file, 1024 * 1024);

if (false === $content) {
$this->error = "fread failed";
@unlink($pathExtracted);
return false;
}

fwrite($output, $content);
fwrite($output, $content);
}
} finally {
fclose($output);
}
fclose($output);

$success = gzclose($file);
if (false === $success) {
Expand Down

0 comments on commit a05a159

Please sign in to comment.