Fixes from the first round of TEST.md
SEO: a domain property (sc-domain:) covers every subdomain, so the shop, Gitea and forum were counted as the website. What ranks, the morning check, the Monday report, keywords, change candidates and the audit's traffic now read only the website's own host (with or without www). The report keeps pages worth a proposal apart from "Waiting for your yes", explains only moves past the thresholds, and says "places up/down". Also: - Feed summaries drop the posts' scripts and styles. - Spend you log can't be negative. - Test and check buttons can't be clicked twice while they run. - Previews show the site's web fonts and icon sprites. - Backups are read without leaving -wal/-shm files; deleting one removes them, and leftovers are swept at start. - The Overview's setup flags a CRM that Hermes can't reach. - Import now says what came in; adding a prospect that exists says so; prospects can be deleted. - Signal tags and brief addresses keep accented letters (Ü → u). - Page errors start with a capital; clearer messages for bad uploads, CRM retry and cancel, keywords, and the finished audit. - The module you're in stays unfolded in the sidebar. - A picked keyword can be unpicked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -135,9 +135,11 @@ func (b *Backup) read() {
|
||||
b.Schema = v
|
||||
}
|
||||
|
||||
// open opens a database file read-only, without touching it.
|
||||
// open opens a database file read-only, without touching it. A backup is
|
||||
// never written to, so it's opened as immutable: SQLite then leaves no -shm
|
||||
// or -wal file next to it, even for a copy in WAL mode.
|
||||
func open(path string) (*sql.DB, error) {
|
||||
d, err := sql.Open("sqlite", "file:"+path+"?mode=ro&_pragma=busy_timeout(5000)")
|
||||
d, err := sql.Open("sqlite", "file:"+path+"?mode=ro&immutable=1&_pragma=busy_timeout(5000)")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -154,11 +156,17 @@ func SchemaOf(path string) (int, error) {
|
||||
defer d.Close()
|
||||
var v int
|
||||
if err := d.QueryRow(`PRAGMA user_version`).Scan(&v); err != nil {
|
||||
return 0, fmt.Errorf("not a database Supermarket can read: %w", err)
|
||||
return 0, ErrNotDatabase
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// What Check says about a file that isn't a backup.
|
||||
var (
|
||||
ErrNotDatabase = errors.New("it isn't a database file")
|
||||
ErrNotSupermarket = errors.New("it's a database, but not a Supermarket one")
|
||||
)
|
||||
|
||||
// Check checks a database file: SQLite's integrity check, and that it's a
|
||||
// Supermarket database (it has the settings table).
|
||||
func Check(path string) error {
|
||||
@@ -169,14 +177,14 @@ func Check(path string) error {
|
||||
defer d.Close()
|
||||
var res string
|
||||
if err := d.QueryRow(`PRAGMA integrity_check`).Scan(&res); err != nil {
|
||||
return fmt.Errorf("not a database Supermarket can read: %w", err)
|
||||
return ErrNotDatabase
|
||||
}
|
||||
if res != "ok" {
|
||||
return fmt.Errorf("the database is damaged: %s", res)
|
||||
}
|
||||
var n int
|
||||
if err := d.QueryRow(`SELECT count(*) FROM sqlite_master WHERE type = 'table' AND name = 'settings'`).Scan(&n); err != nil || n == 0 {
|
||||
return errors.New("that isn't a Supermarket database")
|
||||
return ErrNotSupermarket
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -223,13 +231,37 @@ func Find(dir, name string) (*Backup, error) {
|
||||
return nil, os.ErrNotExist
|
||||
}
|
||||
|
||||
// Delete deletes a backup.
|
||||
// Delete deletes a backup, with any -wal and -shm files left next to it.
|
||||
func Delete(dir, name string) error {
|
||||
b, err := Find(dir, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Remove(b.Path)
|
||||
if err := os.Remove(b.Path); err != nil {
|
||||
return err
|
||||
}
|
||||
removeSidecars(b.Path)
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeSidecars(path string) {
|
||||
os.Remove(path + "-wal")
|
||||
os.Remove(path + "-shm")
|
||||
}
|
||||
|
||||
// RemoveOrphans deletes -wal and -shm files whose backup is gone. Older
|
||||
// versions left them when a backup was deleted. It returns how many.
|
||||
func RemoveOrphans(dir string) int {
|
||||
n := 0
|
||||
for _, suffix := range []string{"-wal", "-shm"} {
|
||||
matches, _ := filepath.Glob(filepath.Join(dir, "app-*.db"+suffix))
|
||||
for _, m := range matches {
|
||||
if _, err := os.Stat(strings.TrimSuffix(m, suffix)); errors.Is(err, os.ErrNotExist) && os.Remove(m) == nil {
|
||||
n++
|
||||
}
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// Keep says which daily backups to keep: the newest 7, then the newest of
|
||||
@@ -274,9 +306,11 @@ func Prune(dir string) (int, error) {
|
||||
if err := os.Remove(b.Path); err != nil {
|
||||
return n, err
|
||||
}
|
||||
removeSidecars(b.Path)
|
||||
n++
|
||||
}
|
||||
}
|
||||
RemoveOrphans(dir)
|
||||
return n, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ func TestCheckNotSupermarket(t *testing.T) {
|
||||
d, _ := sql.Open("sqlite", "file:"+path)
|
||||
d.Exec(`CREATE TABLE x (y)`)
|
||||
d.Close()
|
||||
if err := Check(path); err == nil || !strings.Contains(err.Error(), "isn't a Supermarket database") {
|
||||
if err := Check(path); err == nil || !strings.Contains(err.Error(), "not a Supermarket one") {
|
||||
t.Errorf("check: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -190,3 +190,37 @@ func TestAdoptLegacy(t *testing.T) {
|
||||
t.Errorf("second run moved %d", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteLeavesNoSidecars(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
name := "app-20261121-124721-legacy-phase2.db"
|
||||
src := filepath.Join(t.TempDir(), "src.db")
|
||||
d, err := sql.Open("sqlite", "file:"+src)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d.Exec(`PRAGMA journal_mode = WAL`)
|
||||
d.Exec(`CREATE TABLE settings (key TEXT, value TEXT)`)
|
||||
d.Close()
|
||||
raw, _ := os.ReadFile(src)
|
||||
os.WriteFile(filepath.Join(dir, name), raw, 0o600)
|
||||
if _, err := List(dir); err != nil { // reads each backup's schema
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, suffix := range []string{"-wal", "-shm"} {
|
||||
if _, err := os.Stat(filepath.Join(dir, name+suffix)); err == nil {
|
||||
t.Errorf("listing made %s", suffix)
|
||||
}
|
||||
}
|
||||
os.WriteFile(filepath.Join(dir, name+"-shm"), []byte("x"), 0o600)
|
||||
if err := Delete(dir, name); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
os.WriteFile(filepath.Join(dir, "app-20261120-125700-legacy-phase1.db-wal"), nil, 0o600)
|
||||
if n := RemoveOrphans(dir); n != 1 {
|
||||
t.Errorf("orphans removed: %d", n)
|
||||
}
|
||||
if left, _ := filepath.Glob(filepath.Join(dir, "*")); len(left) != 0 {
|
||||
t.Errorf("left: %v", left)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func TestStageAndApply(t *testing.T) {
|
||||
nd.Close()
|
||||
junk := filepath.Join(t.TempDir(), "junk.db")
|
||||
os.WriteFile(junk, []byte("junk"), 0o600)
|
||||
for src, want := range map[string]string{newer: "newer Supermarket", junk: "not a database", "/nope.db": "no such file"} {
|
||||
for src, want := range map[string]string{newer: "newer Supermarket", junk: "isn't a database", "/nope.db": "no such file"} {
|
||||
if _, err := Stage(cur, data, src, 24, now); err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("%s: %v", src, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user