From 7c6cffbcdecbba60f6667b017c9142aab0ac5586 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 27 Apr 2026 09:44:07 +0300 Subject: fix(processor): handle os.Remove errors for markdown inbox extras When removing markdown inbox extras (embedded local images), os.Remove errors were silently ignored. If removal failed, the image remained in the inbox and was later published as a standalone image post. - Check os.Remove errors and return a wrapped error. - Rollback the already-saved post directory when extra removal fails. - Deduplicate extras to avoid failing on duplicate references (e.g. same image referenced twice in one markdown). - Add a negative test that verifies the error is returned and no post is persisted when removing an embedded image fails. Fixes duplicate image posts caused by leftover inbox extras. --- internal/processor/processor.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'internal/processor/processor.go') diff --git a/internal/processor/processor.go b/internal/processor/processor.go index 0bbc28e..9620e62 100644 --- a/internal/processor/processor.go +++ b/internal/processor/processor.go @@ -169,8 +169,17 @@ func commitPlan(plan postPlan, postsDir string, now time.Time) error { return err } + // Deduplicate extras in case the same file is referenced multiple times. + seen := make(map[string]bool, len(inboxExtras)) for _, path := range inboxExtras { - _ = os.Remove(path) + if seen[path] { + continue + } + seen[path] = true + if err := os.Remove(path); err != nil { + _ = os.RemoveAll(postDir) + return fmt.Errorf("remove inbox extra %s: %w", path, err) + } } return os.Remove(plan.srcPath) -- cgit v1.2.3