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.

48 lines
1.0 KiB

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