Mercurial > gemma
changeset 1227:737e1acea1f1
If there are no XYZ files in the ZIP we cant help the user.
So don't store the ZIP in the temp files.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 19 Nov 2018 18:09:28 +0100 |
parents | 2e65e8ddacab |
children | 17131f0f9fcb |
files | pkg/controllers/srimports.go |
diffstat | 1 files changed, 13 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/controllers/srimports.go Mon Nov 19 17:56:44 2018 +0100 +++ b/pkg/controllers/srimports.go Mon Nov 19 18:09:28 2018 +0100 @@ -162,12 +162,13 @@ var messages []string var result struct { - Token string `json:"token"` + Token string `json:"token,omitempty"` Meta interface{} `json:"meta,omitempty"` Messages []string `json:"messages,omitempty"` } - if common.FindInZIP(zr, ".xyz") == nil { + var noXYZ bool + if noXYZ = common.FindInZIP(zr, ".xyz") == nil; noXYZ { messages = append(messages, "no .xyz file found.") } @@ -188,7 +189,15 @@ } once.Do(closeOnce) - if result.Token, err = misc.MakeTempFile(dir); err != nil { + code := http.StatusCreated + + // If there are no XYZ data we cant help the user anyway. + if noXYZ { + code = status.StatusBadRequest + if err2 := os.RemoveAll(dir); err2 != nil { + log.Printf("error: %v\n", err2) + } + } else if result.Token, err = misc.MakeTempFile(dir); err != nil { if err2 := os.RemoveAll(dir); err2 != nil { log.Printf("error: %v\n", err2) } @@ -198,7 +207,7 @@ result.Messages = messages jr = JSONResult{ - Code: http.StatusCreated, + Code: code, Result: &result, } return