MCPcopy
hub / github.com/wavetermdev/waveterm / DeleteWorkspace

Function DeleteWorkspace

pkg/wcore/workspace.go:120–184  ·  view source on GitHub ↗

If force is true, it will delete even if workspace is named. If workspace is empty, it will be deleted, even if it is named. Returns true if workspace was deleted, false if it was not deleted.

(ctx context.Context, workspaceId string, force bool)

Source from the content-addressed store, hash-verified

118// If workspace is empty, it will be deleted, even if it is named.
119// Returns true if workspace was deleted, false if it was not deleted.
120func DeleteWorkspace(ctx context.Context, workspaceId string, force bool) (bool, string, error) {
121 log.Printf("DeleteWorkspace %s\n", workspaceId)
122 workspace, err := wstore.DBMustGet[*waveobj.Workspace](ctx, workspaceId)
123 if err != nil && wstore.ErrNotFound == err {
124 return true, "", fmt.Errorf("workspace already deleted %w", err)
125 }
126 // @jalileh list needs to be saved early on i assume
127 workspaces, err := ListWorkspaces(ctx)
128 if err != nil {
129 return false, "", fmt.Errorf("error retrieving workspaceList: %w", err)
130 }
131
132 if workspace.Name != "" && workspace.Icon != "" && !force && len(workspace.TabIds) > 0 {
133 log.Printf("Ignoring DeleteWorkspace for workspace %s as it is named\n", workspaceId)
134 return false, "", nil
135 }
136
137 for _, tabId := range workspace.TabIds {
138 log.Printf("deleting tab %s\n", tabId)
139 _, err := DeleteTab(ctx, workspaceId, tabId, false)
140 if err != nil {
141 return false, "", fmt.Errorf("error closing tab: %w", err)
142 }
143 }
144 windowId, _ := wstore.DBFindWindowForWorkspaceId(ctx, workspaceId)
145 err = wstore.DBDelete(ctx, waveobj.OType_Workspace, workspaceId)
146 if err != nil {
147 return false, "", fmt.Errorf("error deleting workspace: %w", err)
148 }
149 log.Printf("deleted workspace %s\n", workspaceId)
150 wps.Broker.Publish(wps.WaveEvent{
151 Event: wps.Event_WorkspaceUpdate,
152 })
153
154 if windowId != "" {
155
156 UnclaimedWorkspace, findAfter := "", false
157 for _, ws := range workspaces {
158 if ws.WorkspaceId == workspaceId {
159 if UnclaimedWorkspace != "" {
160 break
161 }
162 findAfter = true
163 continue
164 }
165 if findAfter && ws.WindowId == "" {
166 UnclaimedWorkspace = ws.WorkspaceId
167 break
168 } else if ws.WindowId == "" {
169 UnclaimedWorkspace = ws.WorkspaceId
170 }
171 }
172
173 if UnclaimedWorkspace != "" {
174 return true, UnclaimedWorkspace, nil
175 } else {
176 err = CloseWindow(ctx, windowId, false)
177 }

Callers 3

DeleteWorkspaceMethod · 0.92
SwitchWorkspaceFunction · 0.85
CloseWindowFunction · 0.85

Calls 7

DBMustGetFunction · 0.92
DBDeleteFunction · 0.92
ListWorkspacesFunction · 0.85
DeleteTabFunction · 0.85
CloseWindowFunction · 0.85
PublishMethod · 0.80

Tested by

no test coverage detected