Skip to content

Commit

Permalink
Don't fail if checksum is not calculated
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioMendolia committed Sep 20, 2023
1 parent d966aff commit 36137ac
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Service/BookFileSystemManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ public function extractCover(Book $book): Book
}

$entries = [];

foreach ($archive->getEntries() as $entry) {
if (str_contains($entry->getPath(), '.jpg') || str_contains($entry->getPath(), '.jpeg')) {
$entries[] = $entry->getPath();
Expand All @@ -374,7 +375,12 @@ public function extractCover(Book $book): Book
$archive->setOutputDirectory('/tmp')->extractEntry($entries[0]); // extract the archive

$filesystem->mkdir($this->getCalculatedImagePath($book, true));
$checksum = $this->getFileChecksum(new \SplFileInfo('/tmp/'.$entries[0]));
try {
$checksum = $this->getFileChecksum(new \SplFileInfo('/tmp/'.$entries[0]));
} catch (\Exception $e) {
$this->logger->error('Could not calculate checksum', ['book' => $bookFile->getRealPath(), 'exception' => $e->getMessage()]);
$checksum = md5(''.time());
}
$filesystem->rename(
'/tmp/'.$entries[0],
$this->getCalculatedImagePath($book, true).$this->getCalculatedImageName($book, $checksum),
Expand Down

0 comments on commit 36137ac

Please sign in to comment.