From 4bcca47ce63b0a68aad4806875fc7331412944cc Mon Sep 17 00:00:00 2001 From: user Date: Tue, 17 Mar 2026 21:42:29 -0700 Subject: [PATCH] fix: remove destructive sync from ListSnapshots ListSnapshots() silently deleted local snapshot records not found in remote storage. A list/read operation should not have destructive side effects. Changes: - Remove the inline deletion loop from ListSnapshots() that deleted local snapshots not present in remote storage - Update syncWithRemote() to use deleteSnapshotFromLocalDB() for proper cascade cleanup (deleting snapshot_files, snapshot_blobs, and snapshot_uploads before the snapshot record itself) The sync behavior remains available via syncWithRemote(), which is called explicitly by PurgeSnapshots(). closes https://git.eeqj.de/sneak/vaultik/issues/15 --- internal/vaultik/snapshot.go | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/internal/vaultik/snapshot.go b/internal/vaultik/snapshot.go index e0d93b2..1697161 100644 --- a/internal/vaultik/snapshot.go +++ b/internal/vaultik/snapshot.go @@ -361,33 +361,6 @@ func (v *Vaultik) ListSnapshots(jsonOutput bool) error { localSnapshotMap[s.ID.String()] = s } - // Remove local snapshots that don't exist remotely - for _, snapshot := range localSnapshots { - snapshotIDStr := snapshot.ID.String() - if !remoteSnapshots[snapshotIDStr] { - log.Info("Removing local snapshot not found in remote", "snapshot_id", snapshot.ID) - - // Delete related records first to avoid foreign key constraints - if err := v.Repositories.Snapshots.DeleteSnapshotFiles(v.ctx, snapshotIDStr); err != nil { - log.Error("Failed to delete snapshot files", "snapshot_id", snapshot.ID, "error", err) - } - if err := v.Repositories.Snapshots.DeleteSnapshotBlobs(v.ctx, snapshotIDStr); err != nil { - log.Error("Failed to delete snapshot blobs", "snapshot_id", snapshot.ID, "error", err) - } - if err := v.Repositories.Snapshots.DeleteSnapshotUploads(v.ctx, snapshotIDStr); err != nil { - log.Error("Failed to delete snapshot uploads", "snapshot_id", snapshot.ID, "error", err) - } - - // Now delete the snapshot itself - if err := v.Repositories.Snapshots.Delete(v.ctx, snapshotIDStr); err != nil { - log.Error("Failed to delete local snapshot", "snapshot_id", snapshot.ID, "error", err) - } else { - log.Info("Deleted local snapshot not found in remote", "snapshot_id", snapshot.ID) - delete(localSnapshotMap, snapshotIDStr) - } - } - } - // Build final snapshot list snapshots := make([]SnapshotInfo, 0, len(remoteSnapshots)) @@ -802,7 +775,7 @@ func (v *Vaultik) syncWithRemote() error { snapshotIDStr := snapshot.ID.String() if !remoteSnapshots[snapshotIDStr] { log.Info("Removing local snapshot not found in remote", "snapshot_id", snapshot.ID) - if err := v.Repositories.Snapshots.Delete(v.ctx, snapshotIDStr); err != nil { + if err := v.deleteSnapshotFromLocalDB(snapshotIDStr); err != nil { log.Error("Failed to delete local snapshot", "snapshot_id", snapshot.ID, "error", err) } else { removedCount++