Skip to content

Commit b84a256

Browse files
authored
[wsman-mk2] Ensure content init can be restarted (#17002)
1 parent d2560e2 commit b84a256

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

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

133+
err = ensureCleanSlate(ws.Location)
134+
if err != nil {
135+
glog.Warnf("cannot ensure clean slate for workspace %s (this might break content init): %v", ws.InstanceID, err)
136+
}
137+
133138
err = content.RunInitializer(ctx, ws.Location, options.Initializer, remoteContent, opts)
134139
if err != nil {
135140
glog.Infof("error running initializer %v", err)
@@ -274,6 +279,25 @@ func (wso *WorkspaceOperations) TakeSnapshot(ctx context.Context, workspaceID, s
274279
return nil
275280
}
276281

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

0 commit comments

Comments
 (0)