Fix noinlineerr findings: internal/vaultik (refs #61)

This commit is contained in:
2026-08-07 16:59:56 +00:00
parent 919229f224
commit e7b49d58ab
10 changed files with 123 additions and 56 deletions
+45 -21
View File
@@ -56,7 +56,8 @@ func (v *Vaultik) CreateSnapshot(opts *SnapshotCreateOptions) error {
// Prune the database before starting: delete incomplete snapshots and orphaned data.
// This ensures the database is consistent before we start a new snapshot.
// Since we use locking, only one vaultik instance accesses the DB at a time.
if _, err := v.PruneDatabase(); err != nil {
_, err = v.PruneDatabase()
if err != nil {
return fmt.Errorf("prune database: %w", err)
}
@@ -195,7 +196,8 @@ func (v *Vaultik) createNamedSnapshot(opts *SnapshotCreateOptions, hostname, sna
v.collectUploadStats(scanner, stats)
if err := v.finalizeSnapshotMetadata(snapshotID, stats); err != nil {
err = v.finalizeSnapshotMetadata(snapshotID, stats)
if err != nil {
return err
}
@@ -395,7 +397,8 @@ func (v *Vaultik) getSnapshotBlobSizes(snapshotID string) (compressed int64, unc
}
for _, hash := range blobHashes {
if blob, err := v.Repositories.Blobs.GetByHash(v.ctx, hash); err == nil && blob != nil {
blob, err := v.Repositories.Blobs.GetByHash(v.ctx, hash)
if err == nil && blob != nil {
compressed += blob.CompressedSize
uncompressed += blob.UncompressedSize
}
@@ -453,7 +456,8 @@ func (v *Vaultik) ListSnapshots(jsonOutput bool) error {
return encoder.Encode(snapshots)
}
if err := v.printSnapshotTable(snapshots); err != nil {
err = v.printSnapshotTable(snapshots)
if err != nil {
return err
}
@@ -552,15 +556,18 @@ func (v *Vaultik) snapshotInfoFromLocal(ls *database.Snapshot) SnapshotInfo {
func (v *Vaultik) printSnapshotTable(snapshots []SnapshotInfo) error {
w := tabwriter.NewWriter(v.Stdout, 0, 0, 3, ' ', 0)
if _, err := fmt.Fprintln(w, "CONFIGURED SNAPSHOTS:"); err != nil {
_, err := fmt.Fprintln(w, "CONFIGURED SNAPSHOTS:")
if err != nil {
return err
}
if _, err := fmt.Fprintln(w, "NAME\tPATHS"); err != nil {
_, err = fmt.Fprintln(w, "NAME\tPATHS")
if err != nil {
return err
}
if _, err := fmt.Fprintln(w, "────\t─────"); err != nil {
_, err = fmt.Fprintln(w, "────\t─────")
if err != nil {
return err
}
@@ -568,16 +575,20 @@ func (v *Vaultik) printSnapshotTable(snapshots []SnapshotInfo) error {
snap := v.Config.Snapshots[name]
paths := strings.Join(snap.Paths, ", ")
if _, err := fmt.Fprintf(w, "%s\t%s\n", name, paths); err != nil {
_, err = fmt.Fprintf(w, "%s\t%s\n", name, paths)
if err != nil {
return err
}
}
if _, err := fmt.Fprintln(w); err != nil {
_, err = fmt.Fprintln(w)
if err != nil {
return err
}
if _, err := fmt.Fprintln(w, "REMOTE SNAPSHOTS:"); err != nil {
_, err = fmt.Fprintln(w, "REMOTE SNAPSHOTS:")
if err != nil {
return err
}
@@ -599,12 +610,13 @@ func (v *Vaultik) printSnapshotTable(snapshots []SnapshotInfo) error {
newChunks = formatBytes(snap.NewChunkSize)
}
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
_, err = fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
snap.ID,
snap.Timestamp.Format("2006-01-02 15:04:05"),
formatBytes(snap.CompressedSize),
uncompressed,
newChunks); err != nil {
newChunks)
if err != nil {
return err
}
}
@@ -626,11 +638,13 @@ type SnapshotPurgeOptions struct {
// snapshot name, not the latest globally. This prevents `home` and `system`
// snapshots from cannibalizing each other.
func (v *Vaultik) PurgeSnapshotsWithOptions(opts *SnapshotPurgeOptions) error {
if err := v.EnsureStorageBinding(); err != nil {
err := v.EnsureStorageBinding()
if err != nil {
return err
}
// Sync with remote first
if err := v.syncWithRemote(); err != nil {
err = v.syncWithRemote()
if err != nil {
return fmt.Errorf("syncing with remote: %w", err)
}
@@ -731,7 +745,9 @@ func (v *Vaultik) confirmAndExecutePurge(toDelete []SnapshotInfo, force, quiet b
v.printfStdout("\nDelete %d snapshot(s)? [y/N] ", len(toDelete))
var confirm string
if _, err := v.scanStdin(&confirm); err != nil {
_, err := v.scanStdin(&confirm)
if err != nil {
// Treat EOF or error as "no"
v.printlnStdout("Cancelled")
@@ -829,7 +845,8 @@ func (v *Vaultik) VerifySnapshotWithOptions(snapshotID string, opts *VerifyOptio
v.printfStdout(" Total size: %s\n", humanize.Bytes(uint64(manifest.TotalCompressedSize)))
if manifest.Timestamp != "" {
if t, err := time.Parse(time.RFC3339, manifest.Timestamp); err == nil {
t, err := time.Parse(time.RFC3339, manifest.Timestamp)
if err == nil {
v.printfStdout(" Created: %s\n", t.Format("2006-01-02 15:04:05 MST"))
}
}
@@ -849,7 +866,9 @@ func (v *Vaultik) VerifySnapshotWithOptions(snapshotID string, opts *VerifyOptio
// Snapshot ID format: hostname[_name]_<RFC3339>
func (v *Vaultik) printVerifyHeader(snapshotID string, opts *VerifyOptions) {
var snapshotTime time.Time
if t, err := parseSnapshotTimestamp(snapshotID); err == nil {
t, err := parseSnapshotTimestamp(snapshotID)
if err == nil {
snapshotTime = t
}
@@ -945,7 +964,8 @@ func (v *Vaultik) outputVerifyJSON(result *VerifyResult) error {
// human ID is hashed via RemoteSnapshotKey and compared against the
// remote listing.
func (v *Vaultik) CleanupLocalSnapshots() error {
if err := v.EnsureStorageBinding(); err != nil {
err := v.EnsureStorageBinding()
if err != nil {
return err
}
@@ -1137,7 +1157,9 @@ func (v *Vaultik) RemoveSnapshot(snapshotID string, opts *RemoveOptions) (*Remov
}
var confirm string
if _, err := v.scanStdin(&confirm); err != nil {
_, err = v.scanStdin(&confirm)
if err != nil {
v.printlnStdout("Cancelled")
return result, nil
@@ -1205,7 +1227,8 @@ func (v *Vaultik) RemoveSnapshot(snapshotID string, opts *RemoveOptions) (*Remov
// "remove --all" leaves nothing behind, even when the local DB and
// remote storage have diverged.
func (v *Vaultik) RemoveAllSnapshots(opts *RemoveOptions) (*RemoveResult, error) {
if err := v.EnsureStorageBinding(); err != nil {
err := v.EnsureStorageBinding()
if err != nil {
return nil, err
}
@@ -1563,7 +1586,8 @@ func (v *Vaultik) PruneDatabase() (*PruneResult, error) {
blobCountBefore, _ := v.getTableCount("blobs")
// Run the cleanup
if err := v.SnapshotManager.CleanupOrphanedData(v.ctx); err != nil {
err = v.SnapshotManager.CleanupOrphanedData(v.ctx)
if err != nil {
return nil, fmt.Errorf("cleanup orphaned data: %w", err)
}