From 31d6cb6f86578ce614c4c366c2630b03d3e75b1f Mon Sep 17 00:00:00 2001 From: James Date: Mon, 23 Mar 2026 14:27:38 -0400 Subject: [PATCH] fix: skip store copy if file already exists (reprocess safety) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- ai.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ai.go b/ai.go index 470b43e..ef9180d 100644 --- a/ai.go +++ b/ai.go @@ -722,10 +722,12 @@ 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 err := copyFile(filePath, storePath); err != nil { - return nil, fmt.Errorf("store copy failed: %w", err) + 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