Skip to content

Commit 2bbc898

Browse files
jchangxclaude
andcommitted
Limit DCR cleanup to successfully removed servers
Pass only the names that were actually removed from the profile to CleanupOrphanedDCREntries, instead of the full user-supplied list. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 89bab26 commit 2bbc898

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pkg/workingset/server.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,18 @@ func RemoveServers(ctx context.Context, dao db.DAO, id string, serverNames []str
9595
namesToRemove[name] = true
9696
}
9797

98-
originalCount := len(workingSet.Servers)
98+
removedNames := make([]string, 0)
9999
filtered := make([]Server, 0, len(workingSet.Servers))
100100
for _, server := range workingSet.Servers {
101101
// TODO: Remove when Snapshot is required
102-
if server.Snapshot == nil || !namesToRemove[server.Snapshot.Server.Name] {
102+
if server.Snapshot != nil && namesToRemove[server.Snapshot.Server.Name] {
103+
removedNames = append(removedNames, server.Snapshot.Server.Name)
104+
} else {
103105
filtered = append(filtered, server)
104106
}
105107
}
106108

107-
removedCount := originalCount - len(filtered)
108-
if removedCount == 0 {
109+
if len(removedNames) == 0 {
109110
return fmt.Errorf("no matching servers found to remove")
110111
}
111112

@@ -120,10 +121,10 @@ func RemoveServers(ctx context.Context, dao db.DAO, id string, serverNames []str
120121
return fmt.Errorf("failed to update profile: %w", err)
121122
}
122123

123-
fmt.Printf("Removed %d server(s) from profile %s\n", removedCount, id)
124+
fmt.Printf("Removed %d server(s) from profile %s\n", len(removedNames), id)
124125

125126
// Clean up DCR entries for removed servers not in any other profile
126-
CleanupOrphanedDCREntries(ctx, dao, serverNames)
127+
CleanupOrphanedDCREntries(ctx, dao, removedNames)
127128

128129
return nil
129130
}

0 commit comments

Comments
 (0)