Skip to content

Edited, moved or deleted images keep their old description: Scan only ever adds to KnownPaths and never prunes stale paths #176

Description

@matt-edmondson

What's wrong

Scan's step 4 (ImageDescriber/Verbs/Scan.cs:77-99) only ever adds a path to an existing record's KnownPaths. Nothing in the project removes one: the only writers of KnownPaths are Scan.cs:89, Scan.cs:216 (new record) and Import.MergeKnownPaths, and none of them removes entries. The only File.Exists check is in Import.

Failure scenario

  1. Scan describes photo.jpg, whose content hashes to H1. Record H1 gets KnownPaths = [photo.jpg].
  2. The user crops or edits photo.jpg. Its content now hashes to H2.
  3. Scan again. H2 gets a new record with [photo.jpg], but H1 still lists photo.jpg.
  4. Search for words from the old description returns photo.jpg with a description of content it no longer has.
  5. Stats over-counts "Total known paths" and "Images found at multiple paths", and Export writes the same path under two hashes.

Files that are deleted or renamed also stay in KnownPaths forever, so Search keeps returning paths that no longer exist.

Suggested fix

After hashing, reconcile each record against the scan:

  • For every known path under the scanned root, drop it if the scan did not find it, or if it now hashes to a different value.
  • Remove records left with no paths, or keep them and report them in the scan summary (e.g. "N descriptions no longer match any file").

Only paths under the scanned root should be touched, so scanning one folder never prunes paths from another.

Acceptance criteria

  • Scan a file, change its bytes, and scan again: the path appears under exactly one hash, the new one.
  • Scan a file, delete it, and scan the same root again: the path is no longer listed.
  • Paths outside the scanned root are untouched.
  • Tests cover all three cases.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions