From 678eccf33dca846487081fce2af9ddf290c1dd60 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 6 Feb 2017 16:18:08 +0000 Subject: [PATCH 1/2] Store bug reports in separate directories --- scripts/rageshake.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/rageshake.go b/scripts/rageshake.go index cd62b4f9e..55dbec85c 100644 --- a/scripts/rageshake.go +++ b/scripts/rageshake.go @@ -37,8 +37,9 @@ func respond(code int, w http.ResponseWriter) { w.Write([]byte("{}")) } -func gzipAndSave(data []byte, fpath string) error { - fpath = filepath.Join("bugs", fpath) +func gzipAndSave(data []byte, dirname, fpath string) error { + _ = os.Mkdir(filepath.Join("bugs", dirname), os.ModePerm) + fpath = filepath.Join("bugs", dirname, fpath) if _, err := os.Stat(fpath); err == nil { return fmt.Errorf("file already exists") // the user can just retry @@ -93,12 +94,12 @@ func main() { summary := fmt.Sprintf( "%s\n\nNumber of logs: %d\nVersion: %s\nUser-Agent: %s\n", p.Text, len(p.Logs), p.Version, p.UserAgent, ) - if err := gzipAndSave([]byte(summary), prefix+".log.gz"); err != nil { + if err := gzipAndSave([]byte(summary), prefix, "details.log.gz"); err != nil { respond(500, w) return } for i, log := range p.Logs { - if err := gzipAndSave([]byte(log.Lines), fmt.Sprintf("%s-%d.log.gz", prefix, i)); err != nil { + if err := gzipAndSave([]byte(log.Lines), prefix, fmt.Sprintf("logs-%d.log.gz", i)); err != nil { respond(500, w) return // TODO: Rollback? } From f16bb85f9b3bf0bc80dadf998b9595ea6ae06015 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 7 Feb 2017 16:04:06 +0000 Subject: [PATCH 2/2] Review comments --- scripts/rageshake.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/rageshake.go b/scripts/rageshake.go index 55dbec85c..b0453b8f3 100644 --- a/scripts/rageshake.go +++ b/scripts/rageshake.go @@ -38,7 +38,7 @@ func respond(code int, w http.ResponseWriter) { } func gzipAndSave(data []byte, dirname, fpath string) error { - _ = os.Mkdir(filepath.Join("bugs", dirname), os.ModePerm) + _ = os.MkdirAll(filepath.Join("bugs", dirname), os.ModePerm) fpath = filepath.Join("bugs", dirname, fpath) if _, err := os.Stat(fpath); err == nil { @@ -90,7 +90,7 @@ func main() { // "bugreport-20170115-112233-1.log.gz" => ... // "bugreport-20170115-112233-N.log.gz" => oldest log t := time.Now().UTC() - prefix := t.Format("bugreport-20060102-150405") + prefix := t.Format("2006-01-02/150405") summary := fmt.Sprintf( "%s\n\nNumber of logs: %d\nVersion: %s\nUser-Agent: %s\n", p.Text, len(p.Logs), p.Version, p.UserAgent, ) @@ -107,6 +107,9 @@ func main() { respond(200, w) }) + // Make sure bugs directory exists + _ = os.Mkdir("bugs", os.ModePerm) + port := os.Args[1] log.Fatal(http.ListenAndServe(":"+port, nil)) }