diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-27 09:44:07 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-27 09:44:07 +0300 |
| commit | 7c6cffbcdecbba60f6667b017c9142aab0ac5586 (patch) | |
| tree | 98b08829ec10d2b78e63b1ffec85e1fa683a423b /internal/processor/processor.go | |
| parent | 06f9809247f8e7c0659271b5fddbe9a063af41d0 (diff) | |
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.
Diffstat (limited to 'internal/processor/processor.go')
| -rw-r--r-- | internal/processor/processor.go | 11 |
1 files changed, 10 insertions, 1 deletions
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) |
