// Canonical 树的旧入口屏障,防止旧快照或子图命令覆盖已迁入的稳定身份模型。 package platform import ( "net/http" "strings" ) // Old frozen receipts remain readable. Old whole-snapshot/ownership writers may // not edit a migrated tree, even when their old client has not seen the barrier. // guardLegacyCanonicalRequest 在 protected 分派前执行;历史回执 GET 可读,但旧快照读取和旧写命令被引导到模型接口。 // 返回 true 表示已经响应 409,调用方必须停止后续业务处理。 func (s *service) guardLegacyCanonicalRequest(w http.ResponseWriter, r *http.Request, project, account string) (bool, error) { if r.PathValue("material") == "" { return false, nil } path := r.URL.Path legacy := strings.HasSuffix(path, "/canvas") if r.Method != http.MethodGet { for _, part := range []string{"/canvas/subgraphs", "/canvas/connections", "/canvas/transactions", "/canvas/operations"} { legacy = legacy || strings.Contains(path, part) } } if !legacy { return false, nil } tx, err := s.db.BeginTx(r.Context(), nil) if err != nil { return false, err } defer tx.Rollback() if _, _, err = lockMaterial(r.Context(), tx, project, r.PathValue("workspace"), r.PathValue("material"), account); err != nil { return false, err } root, err := canonicalRoot(r.Context(), tx, project, r.PathValue("workspace"), r.PathValue("material")) if err != nil { return false, err } if root == "" { return false, nil } reply(w, 409, response{"error": "canonical_write_required", "root_id": root, "model_path": "canvas/model"}) return true, nil }