fix: skip store copy if file already exists (reprocess safety)

When reprocessing a document whose PDF is already in the store,
copyFile() would fail with 'open /srv/docsys/inbox/...: no such file
or directory' because the upload wrote to a temp inbox path that was
already cleaned up by the time async OCR completed.

The store is keyed by content hash so if the file is already there,
the copy is a no-op — skip it rather than error out.
This commit is contained in:
James 2026-03-23 14:27:38 -04:00
parent 883f118d66
commit 31d6cb6f86
1 changed files with 5 additions and 3 deletions

4
ai.go
View File

@ -722,11 +722,13 @@ func ProcessDocument(filePath string) (*Document, error) {
log.Printf(" Category: %s, Type: %s", analysis.Category, analysis.DocType)
// Copy to store
// Copy to store (skip if already there — reprocessing from store-backed upload)
storePath := filepath.Join(storeDir, hash+ext)
if _, statErr := os.Stat(storePath); os.IsNotExist(statErr) {
if err := copyFile(filePath, storePath); err != nil {
return nil, fmt.Errorf("store copy failed: %w", err)
}
}
// Only set PDFPath for actual PDFs — office/text files have no previewable PDF
pdfStorePath := ""