Jobs are to survive a restart in a SQLite database, jobs.db in the state directory, through modernc.org/sqlite v1.64.0 (SQLite 3.54.1), the latest release, which is pure Go and builds with CGO_ENABLED=0. It requires modernc.org/libc at exactly v1.80.1, older than libc's latest; the owner accepted that pin as the one exception to taking dependencies at their latest stable release, and CLAUDE.md and design.md record it here. The other modules it brings are mathutil, memory, go-humanize, go-strftime and bigfft, at the versions it asks for; bigfft has no tagged release. The new package internal/pkg/jobstore opens the database in this order: - It creates the file 0600 if it is missing, since SQLite gives its log the database's mode. An existing file is never opened outside SQLite, since closing any descriptor of it would drop the locks the process holds. - The connection runs its pragmas, in this order: exclusive locking before the first read, so the log's index stays in memory and no -shm file is made; auto_vacuum NONE; WAL; synchronous NORMAL; temporary tables in memory; a 4 MiB journal_size_limit; secure_delete FAST. A connector runs them, since the driver's own _pragma list sorts them by name and would set the locking mode only after the first read, leaving a mapped -shm file on every open but the first. - PRAGMA quick_check reads every page, so a damaged file fails at start rather than when a statement meets the page mid-run. - A user_version newer than the binary's is refused, naming both. - Each schema step runs in one synced transaction that also sets user_version. Version 1 creates jobs, deliveries, content and refs. - It writes once, so a store that cannot be written fails at start and the file stays locked; a second Open of the directory, from any process, fails at once with SQLITE_BUSY. Every error from Open names the file. The URI escapes the path, so a directory with a space, "#", "?" or "%" in its name works. The store syncs with fdatasync where the platform has it, as on Linux. The lock test runs the second Open in a child process, the test binary run again, so the lock tested is the file system's. A test reopens the store three times and finds no -shm file and exclusive locking each time. Nothing uses the store yet. Part of stage 1d of docs/plans/job-store.md (decisions 1, 3 and 13). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
26 lines
516 B
Go
26 lines
516 B
Go
//go:build unix
|
|
|
|
package jobstore
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// The database and its log can be read by the daemon's user only.
|
|
func TestFilesAreTheOwnersAlone(t *testing.T) {
|
|
dir := t.TempDir()
|
|
s := openStore(t, dir)
|
|
fill(t, s, 1)
|
|
for _, name := range []string{FileName, FileName + "-wal"} {
|
|
info, err := os.Stat(filepath.Join(dir, name))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if mode := info.Mode().Perm(); mode != 0o600 {
|
|
t.Errorf("%s has mode %#o, want 0600", name, mode)
|
|
}
|
|
}
|
|
}
|