Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Unified Diff: fiddle/go/fiddle/main.go

Issue 1912793002: fiddle: Don't overwrite existing fiddle names unintentionally. (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | fiddle/go/named/named.go » ('j') | fiddle/go/named/named.go » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fiddle/go/fiddle/main.go
diff --git a/fiddle/go/fiddle/main.go b/fiddle/go/fiddle/main.go
index 53ddcac316298939073f472eb2e2b8159689ff64..88714080658cdca26461df806ab7ef6dfec9805c 100644
--- a/fiddle/go/fiddle/main.go
+++ b/fiddle/go/fiddle/main.go
@@ -52,11 +52,12 @@ var (
//
// It is also used (without the Hash) as the incoming JSON request to /_/run.
type FiddleContext struct {
- Sources string `json:"sources"` // All the source image ids serialized as a JSON array.
- Hash string `json:"fiddlehash"` // Can be the fiddle hash or the fiddle name.
- Code string `json:"code"`
- Name string `json:"name"` // In a request can be the name to create for this fiddle.
- Options types.Options
+ Sources string `json:"sources"` // All the source image ids serialized as a JSON array.
+ Hash string `json:"fiddlehash"` // Can be the fiddle hash or the fiddle name.
+ Code string `json:"code"`
+ Name string `json:"name"` // In a request can be the name to create for this fiddle.
+ Overwrite bool `json:"overwrite"` // In a request, should a name be overwritten if it already exists.
+ Options types.Options
}
// CompileError is a single line of compiler error output, along with the line
@@ -349,7 +350,7 @@ func runHandler(w http.ResponseWriter, r *http.Request) {
ts := repo.Timestamp(gitHash)
fiddleHash, err := fiddleStore.Put(req.Code, req.Options, gitHash, ts, res)
if err != nil {
- httputils.ReportError(w, r, err, "Failed to store the fiddle")
+ httputils.ReportError(w, r, err, "Failed to store the fiddle.")
return
}
resp.FiddleHash = fiddleHash
@@ -358,8 +359,13 @@ func runHandler(w http.ResponseWriter, r *http.Request) {
// Only logged in users can create named fiddles.
if req.Name != "" && user != "" {
// Create a name for this fiddle. Validation is done in this func.
- if err := names.Add(req.Name, fiddleHash, user); err != nil {
- httputils.ReportError(w, r, err, "Failed to store the name")
+ err := names.Add(req.Name, fiddleHash, user, req.Overwrite)
+ if err == named.DuplicateNameErr {
+ httputils.ReportError(w, r, err, "Name already exists.")
+ return
+ }
+ if err != nil {
+ httputils.ReportError(w, r, err, "Failed to store the name.")
return
}
// Replace fiddleHash with name.
« no previous file with comments | « no previous file | fiddle/go/named/named.go » ('j') | fiddle/go/named/named.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698