PictoPy icon indicating copy to clipboard operation
PictoPy copied to clipboard

BUG: Incomplete filesystem scans can delete indexed media records

Open JANAKIRAM218 opened this issue 2 weeks ago • 3 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

What happened?

When PictoPy encounters filesystem access errors during media scanning, such as PermissionError or other OSError exceptions, the scan may return an empty or incomplete list of media files.

The synchronization process can subsequently continue into obsolete-media cleanup, treating media that could not be inspected as missing. This can result in existing image or video records being deleted from the database even though the underlying files still exist.

This is particularly dangerous when scanning external drives, mounted directories, or libraries containing folders with restricted permissions or temporary filesystem access failures.

Steps to Reproduce

  1. Add a folder containing images and/or videos to PictoPy.
  2. Allow the initial scan to complete so that the media is indexed in the database.
  3. Verify that the indexed media appears in PictoPy.
  4. Temporarily restrict read/list permissions on the indexed directory or one of its subdirectories, or simulate a filesystem access failure.
  5. Trigger folder synchronization.
  6. Restore the original filesystem permissions.
  7. Check whether previously indexed media records have been removed from PictoPy despite the corresponding files still existing on disk.

Expected Behavior

  • A failed or incomplete filesystem scan should not be interpreted as a successful scan containing zero media files.
  • Existing indexed media records should be preserved when directories cannot be accessed or enumerated.
  • Obsolete-media cleanup should only run for directories that were scanned successfully and completely.
  • Temporary permission errors, unavailable external drives, and filesystem access failures should not cause indexed media or their associated metadata to be deleted.

Actual Behavior

Based on the synchronization and cleanup code paths, filesystem scan errors may be caught and converted into empty or partial scan results without reliably indicating that the scan failed.

The synchronization process can still reach obsolete-media cleanup, where media that was not discovered during the incomplete scan may be treated as deleted.

This can cause existing database records and associated data, including thumbnails and AI-generated metadata, to be removed even though the original media files have not actually been deleted.

Impact

  • Existing images or videos may disappear from the PictoPy library.
  • Indexed metadata may be deleted.
  • AI-generated tags, face data, embeddings, and related records may be lost depending on database relationships and cleanup behavior.
  • External-drive disconnections or temporary permission problems may result in unintended library data loss.
  • Users may need to rescan and reprocess media to restore their library state.

Suggested Fix

  • Distinguish successful, incomplete, and failed directory scans.
  • Prevent obsolete-media cleanup from running against incomplete scan results.
  • Preserve indexed records when filesystem access fails or the scan cannot reliably establish that media is missing.
  • Make cleanup error-aware instead of treating inaccessible paths as confirmed deletions.
  • Add regression tests covering permission failures, inaccessible subdirectories, failed directory enumeration, and unavailable external storage.

Record

  • [x] I agree to follow this project's Code of Conduct

JANAKIRAM218 avatar Nov 20 '26 13:11 JANAKIRAM218

👋 Thanks for opening this issue! The maintainers will review it shortly. Till then, do not open any PR. This is a strict rule we like to follow around here :)

Discussions are carried on Discord.

Instead of commenting here, join the AOSSIE Discord server and go to Projects → PictoPy.

If you find this project useful, a GitHub star would be appreciated.

github-actions[bot] avatar Nov 20 '26 13:11 github-actions[bot]

Link your account with Gitcord

Thanks for opening this issue, @JANAKIRAM218!

To receive Discord notifications and contributor tracking for this organization:

  1. Join Discord: https://discord.gg/hjUhu33uAn
  2. In Discord, run /link JANAKIRAM218
  3. Paste the verification code into your GitHub bio (or a public gist)
  4. Click Verify in Discord (or run /verify-link JANAKIRAM218)

Once linked, Gitcord can notify you about assignments, mentions, and more.

— Posted by Gitcord

gitcordapp[bot] avatar Nov 20 '26 13:11 gitcordapp[bot]

@rohan-pandeyy i want to work on this issue can i get assigned to it?

swastiksharma45 avatar Nov 21 '26 10:11 swastiksharma45