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.

31 lines
699 B

  1. package operation
  2. import (
  3. "code.google.com/p/weed-fs/go/glog"
  4. "code.google.com/p/weed-fs/go/storage"
  5. "net/http"
  6. )
  7. func DeleteFile(server string, fileId string) error {
  8. fid, parseErr := storage.ParseFileId(fileId)
  9. if parseErr != nil {
  10. return parseErr
  11. }
  12. lookup, lookupError := Lookup(server, fid.VolumeId)
  13. if lookupError != nil {
  14. return lookupError
  15. }
  16. if len(lookup.Locations) == 0 {
  17. return nil
  18. }
  19. return Delete("http://" + lookup.Locations[0].PublicUrl + "/" + fileId)
  20. }
  21. func Delete(url string) error {
  22. req, err := http.NewRequest("DELETE", url, nil)
  23. if err != nil {
  24. glog.V(0).Infoln("failing to delete", url)
  25. return err
  26. }
  27. _, err = http.DefaultClient.Do(req)
  28. return err
  29. }