1
0
mirror of https://github.com/golang/go synced 2024-11-14 14:40:23 -07:00
go/misc/dashboard/app/build/init.go
David Symonds e6c5e2a363 misc/dashboard: cope with removed Package fields.
adg removed some now-unwanted fields in Package a while ago,
but there are still datastore entities with those fields,
so we must explicitly check for ErrFieldMismatch and ignore it.

R=golang-dev, rsc
CC=adg, golang-dev
https://golang.org/cl/6007043
2012-04-12 09:55:37 +10:00

63 lines
1.3 KiB
Go

// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package build
import (
"fmt"
"net/http"
"appengine"
"appengine/datastore"
"cache"
)
// defaultPackages specifies the Package records to be created by initHandler.
var defaultPackages = []*Package{
{Name: "Go", Kind: "go"},
}
// subRepos specifies the Go project sub-repositories.
var subRepos = []string{
"codereview",
"crypto",
"image",
"net",
}
// Put subRepos into defaultPackages.
func init() {
for _, name := range subRepos {
p := &Package{
Kind: "subrepo",
Name: "go." + name,
Path: "code.google.com/p/go." + name,
}
defaultPackages = append(defaultPackages, p)
}
}
func initHandler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
defer cache.Tick(c)
for _, p := range defaultPackages {
err := datastore.Get(c, p.Key(c), new(Package))
if _, ok := err.(*datastore.ErrFieldMismatch); ok {
// Some fields have been removed, so it's okay to ignore this error.
err = nil
}
if err == nil {
continue
} else if err != datastore.ErrNoSuchEntity {
logErr(w, r, err)
return
}
if _, err := datastore.Put(c, p.Key(c), p); err != nil {
logErr(w, r, err)
return
}
}
fmt.Fprint(w, "OK")
}