A bounce could be recorded as a successful delivery. The log-tailer's Fixed: - A bounce could be recorded as a successful delivery. The log-tailer's - Log-tailer resumes where it stopped instead of jumping to end-of-file on - Level-2 rate limit no longer overshoots under concurrency: messages that Changed: - The project has a single public home: `github.com/mixeme/selfpost`. Codeberg - Code comments no longer cite the archived specification. References like - `docs/code-review.md` is gone. Its plan is finished — phases 0 (bar the - `docs/architecture.md` gained a *Code layers* section: a diagram of - Phase 1 doc/code hygiene (`docs/code-review.md`): removed ~30 stale … (1 more in CHANGELOG) Security: - Pre-release security review (plan § D, model Fable, 2026-08-06): full pass - `saslpasswd2` argv: the application login is now passed after a `--` Added: - Optional password encryption for the two secret-bearing downloads (plan - Domain import accepts an encrypted export: the envelope is detected by its - `selfpost-backup` writes encrypted archives and reads them back: - `TestParseDelivery` covers the exotic mail.log shapes the review asked for - docs: README *Encrypting a backup or export*; `docs/security.md` § … (14 more in CHANGELOG) Removed: - docs: `security.md` — accepted risk «restore old backup revives session rows» Changed: - docs: `implementation-plan.md` trimmed to the sole open v1.x gate — pre-release - docs: `architecture.md` — sessions (SQLite, idle renew, password change), - docs: `development.md` — expanded e2e stack and `release.yml` matrix workflow. - docs: `security.md` — accepted risk for send-log rows stuck at `queued` after - docs: `roadmap.md` — optional send-log / `mail.log` follow-ups under v1.x tail. … (10 more in CHANGELOG) Full detail: CHANGELOG.md (0.5.0).
55 lines
1.7 KiB
Go
55 lines
1.7 KiB
Go
package store
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// LogtailState is the persisted read position of the mail.log tailer: how far
|
|
// into the log it had got, and a fingerprint of the file that offset refers to.
|
|
// It lets the tailer resume after a panel restart instead of jumping to
|
|
// end-of-file and losing the delivery lines written while it was down.
|
|
type LogtailState struct {
|
|
Fingerprint string
|
|
Offset int64
|
|
}
|
|
|
|
// LogtailState returns the stored read position for path. ok is false the first
|
|
// time a path is followed (nothing persisted yet), which the tailer treats as
|
|
// "start at the end".
|
|
func (s *Store) LogtailState(path string) (LogtailState, bool, error) {
|
|
var st LogtailState
|
|
err := s.db.QueryRow(
|
|
`SELECT fingerprint, read_offset FROM logtail_state WHERE path = ?`,
|
|
path,
|
|
).Scan(&st.Fingerprint, &st.Offset)
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return LogtailState{}, false, nil
|
|
}
|
|
if err != nil {
|
|
return LogtailState{}, false, fmt.Errorf("read logtail state for %q: %w", path, err)
|
|
}
|
|
return st, true, nil
|
|
}
|
|
|
|
// SaveLogtailState records the tailer's read position for path, replacing any
|
|
// previous one. It is called on a timer while tailing, so it is a single small
|
|
// upsert rather than a transaction.
|
|
func (s *Store) SaveLogtailState(path string, st LogtailState) error {
|
|
_, err := s.db.Exec(
|
|
`INSERT INTO logtail_state (path, fingerprint, read_offset, updated_at)
|
|
VALUES (?, ?, ?, ?)
|
|
ON CONFLICT(path) DO UPDATE SET
|
|
fingerprint = excluded.fingerprint,
|
|
read_offset = excluded.read_offset,
|
|
updated_at = excluded.updated_at`,
|
|
path, st.Fingerprint, st.Offset, time.Now().UTC().Format(time.RFC3339),
|
|
)
|
|
if err != nil {
|
|
return fmt.Errorf("save logtail state for %q: %w", path, err)
|
|
}
|
|
return nil
|
|
}
|