nextcloud / nextcloud/server

[Bug]: Preview generation fails when DB entry exists, but local file does not

Open
#63,349 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0. Needs triage 35-feedback bug feature: previews and thumbnails regression
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

⚠️ This issue respects the following points: ⚠️
Bug description

If we end up in the situation that the DB entry exists, but the file does not, we are unable to re-generate the preview via occ, we end up with:

root@nextcloud:/var/www/nextcloud# occ preview:generate 1411721

In LocalPreviewStorage.php line 59:
                                                                                                                            
  Unable to open preview stream at /var/nextcloud/data/appdata_oc4r8rpp6vq8/preview/d/2/c/e/d/1/3/1411721/1024-768-max.jpg  
                                                                                                                            

preview:generate [-s|--size SIZE] [-c|--crop] [-m|--mode MODE] [--] <file>

root@nextcloud:/var/www/nextcloud# vi lib/private/Preview/Storage/LocalPreviewStorage.php 
root@nextcloud:/var/www/nextcloud# occ preview:generate 1411721
#0 /var/www/nextcloud/lib/private/Preview/Storage/StorageFactory.php(32): OC\Preview\Storage\LocalPreviewStorage->readPreview(Object(OC\Preview\Db\Preview))
#1 /var/www/nextcloud/lib/private/Preview/Storage/PreviewFile.php(48): OC\Preview\Storage\StorageFactory->readPreview(Object(OC\Preview\Db\Preview))
#2 /var/www/nextcloud/lib/private/Preview/GeneratorHelper.php(30): OC\Preview\Storage\PreviewFile->getContent()
#3 /var/www/nextcloud/lib/private/Preview/Generator.php(180): OC\Preview\GeneratorHelper->getImage(Object(OC\Preview\Storage\PreviewFile))
#4 /var/www/nextcloud/lib/private/PreviewManager.php(203): OC\Preview\Generator->generatePreviews(Object(OC\Files\Node\File), Array, '...')
#5 /var/www/nextcloud/core/Command/Preview/Generate.php(94): OC\PreviewManager->generatePreviews(Object(OC\Files\Node\File), Array)
#6 /var/www/nextcloud/3rdparty/symfony/console/Command/Command.php(326): OC\Core\Command\Preview\Generate->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /var/www/nextcloud/3rdparty/symfony/console/Application.php(1098): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 /var/www/nextcloud/3rdparty/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand(Object(OC\Core\Command\Preview\Generate), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 /var/www/nextcloud/3rdparty/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 /var/www/nextcloud/lib/private/Console/Application.php(209): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /var/www/nextcloud/console.php(92): OC\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput))
#12 /var/www/nextcloud/occ(33): require_once('...')

Best case would probably even be automatic handling for that case?

Nextcloud Server version

35 (master)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/private/Preview/Storage/LocalPreviewStorage.php, especially the failing readPreview path shown in the stack trace, then follow how occ preview:generate reaches it through StorageFactory.php, PreviewFile.php, and Generator.php. Run occ preview:generate for a file whose database entry exists but local preview file is missing. Done means that case is handled automatically and preview generation can proceed without the stream error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
57/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.