Skip to content

Commit

Permalink
Merge pull request #1018 from nextcloud/fix/992
Browse files Browse the repository at this point in the history
fix(Classifier): Don't hang because of empty file
  • Loading branch information
marcelklehr authored Nov 5, 2023
2 parents e1e04b4 + 72e83e2 commit cd4836b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/Classifiers/Classifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCA\Recognize\Service\QueueService;
use OCP\DB\Exception;
use OCP\Files\File;
use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
Expand Down Expand Up @@ -86,6 +87,16 @@ public function classifyFiles(string $model, array $queueFiles, int $timeout): \
continue;
}
try {
if ($files[0]->getSize() == 0) {
$this->logger->debug('File is empty: ' . $files[0]->getPath());
try {
$this->logger->debug('removing ' . $queueFile->getFileId() . ' from ' . $model . ' queue');
$this->queue->removeFromQueue($model, $queueFile);
} catch (Exception $e) {
$this->logger->warning($e->getMessage(), ['exception' => $e]);
}
continue;
}
$path = $this->getConvertedFilePath($files[0]);
if (in_array($model, [ImagenetClassifier::MODEL_NAME, LandmarksClassifier::MODEL_NAME, ClusteringFaceClassifier::MODEL_NAME], true)) {
// Check file data size
Expand Down Expand Up @@ -116,7 +127,7 @@ public function classifyFiles(string $model, array $queueFiles, int $timeout): \
$paths[] = $path;
$processedFiles[] = $queueFile;
$fileNames[] = $files[0]->getPath();
} catch (NotFoundException $e) {
} catch (NotFoundException|InvalidPathException $e) {
$this->logger->warning('Could not find file', ['exception' => $e]);
try {
$this->queue->removeFromQueue($model, $queueFile);
Expand Down

0 comments on commit cd4836b

Please sign in to comment.