@@ -66,6 +66,8 @@ type WorkspaceOperations interface {
6666 BackupWorkspace (ctx context.Context , opts BackupOptions ) (* csapi.GitStatus , error )
6767 // DeleteWorkspace deletes the content of the workspace from disk
6868 DeleteWorkspace (ctx context.Context , instanceID string ) error
69+ // WipeWorkspace deletes all references to the workspace. Does not fail if parts are already gone, or state is incosistent.
70+ WipeWorkspace (ctx context.Context , instanceID string ) error
6971 // SnapshotIDs generates the name and url for a snapshot
7072 SnapshotIDs (ctx context.Context , instanceID string ) (snapshotUrl , snapshotName string , err error )
7173 // Snapshot takes a snapshot of the workspace
@@ -285,6 +287,36 @@ func (wso *DefaultWorkspaceOperations) DeleteWorkspace(ctx context.Context, inst
285287 return nil
286288}
287289
290+ func (wso * DefaultWorkspaceOperations ) WipeWorkspace (ctx context.Context , instanceID string ) error {
291+ ws , err := wso .provider .GetAndConnect (ctx , instanceID )
292+ if err != nil {
293+ // we have to assume everything is fine, and this workspace has already been completely wiped
294+ return nil
295+ }
296+
297+ if err = ws .Dispose (ctx , wso .provider .hooks [session .WorkspaceDisposed ]); err != nil {
298+ glog .WithError (err ).WithFields (ws .OWI ()).Error ("cannot dispose session" )
299+ return err
300+ }
301+
302+ // remove workspace daemon directory in the node
303+ if err := os .RemoveAll (ws .ServiceLocDaemon ); err != nil {
304+ glog .WithError (err ).WithFields (ws .OWI ()).Error ("cannot delete workspace daemon directory" )
305+ return err
306+ }
307+
308+ // remove workspace daemon node directory in the node
309+ // TODO(gpl): Is this used at all? Can't find any reference
310+ if err := os .RemoveAll (ws .ServiceLocNode ); err != nil {
311+ glog .WithError (err ).WithFields (ws .OWI ()).Error ("cannot delete workspace daemon node directory" )
312+ return err
313+ }
314+
315+ wso .provider .Remove (ctx , instanceID )
316+
317+ return nil
318+ }
319+
288320func (wso * DefaultWorkspaceOperations ) SnapshotIDs (ctx context.Context , instanceID string ) (snapshotUrl , snapshotName string , err error ) {
289321 sess , err := wso .provider .GetAndConnect (ctx , instanceID )
290322 if err != nil {
0 commit comments