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:
parent
883f118d66
commit
31d6cb6f86
4
ai.go
4
ai.go
|
|
@ -722,11 +722,13 @@ func ProcessDocument(filePath string) (*Document, error) {
|
||||||
|
|
||||||
log.Printf(" Category: %s, Type: %s", analysis.Category, analysis.DocType)
|
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)
|
storePath := filepath.Join(storeDir, hash+ext)
|
||||||
|
if _, statErr := os.Stat(storePath); os.IsNotExist(statErr) {
|
||||||
if err := copyFile(filePath, storePath); err != nil {
|
if err := copyFile(filePath, storePath); err != nil {
|
||||||
return nil, fmt.Errorf("store copy failed: %w", err)
|
return nil, fmt.Errorf("store copy failed: %w", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Only set PDFPath for actual PDFs — office/text files have no previewable PDF
|
// Only set PDFPath for actual PDFs — office/text files have no previewable PDF
|
||||||
pdfStorePath := ""
|
pdfStorePath := ""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue