All checks were successful
check / check (push) Successful in 5s
Updates golangci-lint to v2.12.2 everywhere it is pinned and installs the canonical `.golangci.yml`, then remediates every finding the new linter/config surfaces so `make check` is green. ## Version bump - `Dockerfile` lint stage: `golangci/golangci-lint:v2.11.3-alpine` -> `v2.12.2-alpine` (digest-pinned, date comment updated) - `Makefile` `deps` target: `go install` moved from the old v1 module path at `@latest` to the pinned `github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2` - `.golangci.yml` replaced with the canonical config (v2 schema; settings under `linters.settings` so the thresholds actually apply; `default: all` with the standard six disables) - `script/bootstrap` installs golangci-lint via the system package manager and carries no version pin, so it is unchanged - CI (`.gitea/workflows/check.yml`) only runs `script/cibuild`, so it needed no change ## Lint remediation The canonical config surfaced ~3,300 findings across 56k lines. All are fixed, behavior-preserving; incorporates and supersedes the per-package mechanical passes already merged to `main` (refs #61). Highlights: - `err113`: dynamic errors replaced with package sentinels + `%w` wrapping; comparisons via `errors.Is` - `goprintffuncname`: printf-style helpers renamed with an `f` suffix (`ui.Writer` message methods, `cli.ReportErrorf`, `database.Fatalf`) and all call sites updated - `revive` stutter renames: `blob.Handler`, `blob.WithReader`, `blob.ChunkPosition`, `storage.URL`, `storage.Info`; missing doc comments added - `contextcheck`/`noctx`: `context.Context` threaded through `blob.Packer` and the scanner call sites; context-aware `exec`/`sql` variants - `funlen`/`cyclop`/`gocognit`/`dupl`: oversized and duplicated functions split into focused helpers (production and test code) - tests: `t.Parallel()` added where safe (global logger init kept in the serial phase for `-race`), `t.TempDir()`/`t.Helper()` adopted, several suites converted to external test packages - `gosec`: bounded integer conversions, `ReadHeaderTimeout` on the test HTTP server; remaining warnings suppressed per-site with justifications - remaining `nolint` directives are rare, targeted, and each carries a reason (e.g. `nilnil` not-found contract in the repository layer, fx module globals, on-disk snake_case struct tags) - removed the deprecated `log.LogOptions` alias (callers migrated to `log.Options`) `make check` (tests with `-race`, lint, fmt-check) passes. Co-authored-by: sneak <sneak@sneak.berlin> Reviewed-on: #62 Co-authored-by: clawbot <clawbot@noreply.example.org> Co-committed-by: clawbot <clawbot@noreply.example.org>
118 lines
2.9 KiB
Go
118 lines
2.9 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
"sneak.berlin/go/vaultik/internal/config"
|
|
"sneak.berlin/go/vaultik/internal/log"
|
|
)
|
|
|
|
// NewDatabaseCommand creates the database command group
|
|
func NewDatabaseCommand() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "database",
|
|
Short: "Manage the local state database",
|
|
Long: `Commands for managing the local SQLite state database.`,
|
|
}
|
|
|
|
cmd.AddCommand(
|
|
newDatabaseDeleteCommand(),
|
|
)
|
|
|
|
return cmd
|
|
}
|
|
|
|
// newDatabaseDeleteCommand creates the database delete command.
|
|
// (Renamed from "purge"; the operation removes the SQLite file
|
|
// entirely, which is a delete, not a purge of content.)
|
|
func newDatabaseDeleteCommand() *cobra.Command {
|
|
var force bool
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "delete",
|
|
Short: "Delete the local state database file",
|
|
Long: `Completely removes the local SQLite state database.
|
|
|
|
This will erase all local tracking of:
|
|
- File metadata and change detection state
|
|
- Chunk and blob mappings
|
|
- Local snapshot records
|
|
- The storage-binding record
|
|
|
|
The remote storage is NOT affected. After deletion, the next backup
|
|
will perform a full scan and re-deduplicate against existing remote
|
|
blobs, and the local index will re-bind to the currently configured
|
|
storage destination on that run.
|
|
|
|
Use --force to skip the confirmation prompt.`,
|
|
Args: cobra.NoArgs,
|
|
RunE: func(_ *cobra.Command, _ []string) error {
|
|
// Resolve config path
|
|
configPath, err := ResolveConfigPath()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Load config to get database path
|
|
cfg, err := config.Load(configPath)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to load config: %w", err)
|
|
}
|
|
|
|
dbPath := cfg.IndexPath
|
|
|
|
// Check if database exists
|
|
_, err = os.Stat(dbPath)
|
|
if os.IsNotExist(err) {
|
|
_, _ = fmt.Fprintf(os.Stdout, "Database does not exist: %s\n", dbPath)
|
|
|
|
return nil
|
|
}
|
|
|
|
// Confirm unless --force
|
|
if !force {
|
|
_, _ = fmt.Fprintf(os.Stdout,
|
|
"This will delete the local state database at:\n %s\n\n", dbPath)
|
|
_, _ = fmt.Fprint(os.Stdout, "Are you sure? Type 'yes' to confirm: ")
|
|
|
|
var confirm string
|
|
|
|
_, err = fmt.Scanln(&confirm)
|
|
if err != nil || confirm != "yes" {
|
|
_, _ = fmt.Fprintln(os.Stdout, "Aborted.")
|
|
|
|
//nolint:nilerr // a failed/aborted confirmation is a clean abort
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// Delete the database file
|
|
err = os.Remove(dbPath)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to delete database: %w", err)
|
|
}
|
|
|
|
// Also delete WAL and SHM files if they exist
|
|
walPath := dbPath + "-wal"
|
|
shmPath := dbPath + "-shm"
|
|
_ = os.Remove(walPath) // Ignore errors - files may not exist
|
|
_ = os.Remove(shmPath)
|
|
|
|
rootFlags := GetRootFlags()
|
|
if !rootFlags.Quiet {
|
|
_, _ = fmt.Fprintf(os.Stdout, "Database deleted: %s\n", dbPath)
|
|
}
|
|
|
|
log.Info("Local state database deleted", "path", dbPath)
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
cmd.Flags().BoolVar(&force, "force", false, "Skip confirmation prompt")
|
|
|
|
return cmd
|
|
}
|