Skip to content

Commit 2f04cac

Browse files
committed
[wsman-mk2] Ensure content init can be restarted
1 parent 93eb0eb commit 2f04cac

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

components/ws-daemon/pkg/controller/workspace_operations.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func (wso *WorkspaceOperations) InitWorkspaceContent(ctx context.Context, option
130130
},
131131
}
132132

133+
ensureCleanSlate(ws.Location)
133134
err = content.RunInitializer(ctx, ws.Location, options.Initializer, remoteContent, opts)
134135
if err != nil {
135136
glog.Infof("error running initializer %v", err)
@@ -274,6 +275,25 @@ func (wso *WorkspaceOperations) TakeSnapshot(ctx context.Context, workspaceID, s
274275
return nil
275276
}
276277

278+
func ensureCleanSlate(location string) error {
279+
// do not remove the location itself but only
280+
// the children
281+
files, err := os.ReadDir(location)
282+
if err != nil {
283+
return err
284+
}
285+
286+
for _, f := range files {
287+
path := filepath.Join(location, f.Name())
288+
err = os.RemoveAll(path)
289+
if err != nil {
290+
return err
291+
}
292+
}
293+
294+
return nil
295+
}
296+
277297
func (wso *WorkspaceOperations) uploadWorkspaceLogs(ctx context.Context, opts DisposeOptions) (err error) {
278298
// currently we're only uploading prebuild log files
279299
logFiles, err := logs.ListPrebuildLogFiles(ctx, opts.WorkspaceLocation)

0 commit comments

Comments
 (0)