add random string to report directories to prevent time-based collisions
This commit is contained in:
parent
065b2b9a04
commit
86b4ccc1df
3 changed files with 8 additions and 0 deletions
1
changelog.d/39.bugfix
Normal file
1
changelog.d/39.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Prevent timestamp collisions when reports are submitted within 1 second of each other.
|
2
main.go
2
main.go
|
@ -23,6 +23,7 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -146,6 +147,7 @@ func main() {
|
|||
}
|
||||
log.Printf("Using %s/listing as public URI", apiPrefix)
|
||||
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
http.Handle("/api/submit", &submitServer{ghClient, glClient, apiPrefix, slack, cfg})
|
||||
|
||||
// Make sure bugs directory exists
|
||||
|
|
|
@ -20,11 +20,13 @@ import (
|
|||
"bytes"
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"encoding/base32"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
"mime"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
|
@ -145,6 +147,9 @@ func (s *submitServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
// files straight in
|
||||
t := time.Now().UTC()
|
||||
prefix := t.Format("2006-01-02/150405")
|
||||
randBytes := make([]byte, 5)
|
||||
rand.Read(randBytes)
|
||||
prefix += "-" + base32.StdEncoding.EncodeToString(randBytes)
|
||||
reportDir := filepath.Join("bugs", prefix)
|
||||
if err := os.MkdirAll(reportDir, os.ModePerm); err != nil {
|
||||
log.Println("Unable to create report directory", err)
|
||||
|
|
Reference in a new issue