fix: delete instance data and remove legacy shared workspace support

This commit is contained in:
2026-10-15 10:55:21 +08:00
parent ee22603726
commit 22a5f64edc
16 changed files with 286 additions and 142 deletions
+11 -10
View File
@@ -167,6 +167,10 @@ func (a *API) createRuntime(ctx context.Context, u store.User, i store.Instance,
return
}
}
if err := a.removeInstanceData(i); err != nil {
a.s.SetInstance(i.ID, "error")
return
}
a.s.DeleteInstance(i.ID)
_, _ = a.s.DB.Exec("DELETE FROM runtime_networks WHERE instance_id=?", i.ID)
_, _ = a.s.DB.Exec("DELETE FROM runtime_creates WHERE instance_id=?", i.ID)
@@ -191,7 +195,7 @@ func (a *API) createRuntime(ctx context.Context, u store.User, i store.Instance,
return i, errors.New("storage unavailable")
}
suffix := filepath.Join("workspaces", u.ID)
for _, relative := range []string{filepath.Join(suffix, "files"), filepath.Join(suffix, "instances", i.ID, "home")} {
for _, relative := range []string{filepath.Join(suffix, "instances", i.ID, "home")} {
dir := filepath.Join(root, relative)
if err := os.MkdirAll(dir, 0750); err != nil {
return i, errors.New("storage unavailable")
@@ -258,14 +262,6 @@ func (a *API) createRuntime(ctx context.Context, u store.User, i store.Instance,
},
},
}
if policy.RecipeRev != "7" {
sharedSource, err := toHostPath(root, hostRoot, filepath.Join(root, suffix, "files"))
if err != nil {
return i, err
}
body["Env"] = []string{"DSH_HOME=/data/dsh-home", "HOME=/data/dsh-home", "XDG_DATA_HOME=/data/dsh-home/.local/share", "XDG_CONFIG_HOME=/data/dsh-home/.config"}
body["HostConfig"].(map[string]any)["Mounts"] = []map[string]any{{"Type": "bind", "Source": homeSource, "Target": "/data/dsh-home"}, {"Type": "bind", "Source": sharedSource, "Target": "/workspace"}}
}
var created struct {
ID string `json:"Id"`
}
@@ -415,12 +411,17 @@ func (a *API) instance(w http.ResponseWriter, r *http.Request) {
fail(w, 502, "network deletion failed")
return
}
if err := a.removeInstanceData(i); err != nil {
a.s.SetInstance(i.ID, "error")
fail(w, 500, "instance data deletion failed; retry deletion")
return
}
if _, err := a.s.DB.ExecContext(ctx, "DELETE FROM instances WHERE id=?", i.ID); err != nil {
fail(w, 500, "database error")
return
}
_, _ = a.s.DB.Exec("DELETE FROM runtime_networks WHERE instance_id=?", i.ID)
a.s.AddAudit(u.ID, "instance.delete", i.ID, "data retained")
a.s.AddAudit(u.ID, "instance.delete", i.ID, "instance data deleted")
// The instance row is gone and its resources were just cleaned, so
// any pending flags cannot resolve later: drop the row unconditionally.
_, _ = a.s.DB.Exec("DELETE FROM runtime_creates WHERE instance_id=?", i.ID)