Contains the Concourse pipeline definition for building a line-server container
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.0 KiB

  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "os"
  6. "path"
  7. "github.com/zenazn/goji/web"
  8. )
  9. func deleteHandler(c web.C, w http.ResponseWriter, r *http.Request) {
  10. requestKey := r.Header.Get("X-Delete-Key")
  11. filename := c.URLParams["name"]
  12. filePath := path.Join(Config.filesDir, filename)
  13. metaPath := path.Join(Config.metaDir, filename)
  14. // Ensure requested file actually exists
  15. if _, readErr := os.Stat(filePath); os.IsNotExist(readErr) {
  16. notFoundHandler(c, w, r) // 404 - file doesn't exist
  17. return
  18. }
  19. // Ensure delete key is correct
  20. deleteKey, err := metadataGetDeleteKey(filename)
  21. if err != nil {
  22. unauthorizedHandler(c, w, r) // 401 - no metadata available
  23. return
  24. }
  25. if deleteKey == requestKey {
  26. fileDelErr := os.Remove(filePath)
  27. metaDelErr := os.Remove(metaPath)
  28. if (fileDelErr != nil) || (metaDelErr != nil) {
  29. oopsHandler(c, w, r, RespPLAIN, "Could not delete")
  30. return
  31. }
  32. fmt.Fprintf(w, "DELETED")
  33. return
  34. } else {
  35. unauthorizedHandler(c, w, r) // 401 - wrong delete key
  36. return
  37. }
  38. }