2012-09-26 18:27:10 +08:00
|
|
|
package operation
|
|
|
|
|
|
|
|
import (
|
2013-08-09 14:57:22 +08:00
|
|
|
"code.google.com/p/weed-fs/go/glog"
|
2013-08-14 15:31:02 +08:00
|
|
|
"code.google.com/p/weed-fs/go/storage"
|
2013-01-17 16:56:56 +08:00
|
|
|
"net/http"
|
2012-09-26 18:27:10 +08:00
|
|
|
)
|
|
|
|
|
2013-09-02 14:58:21 +08:00
|
|
|
func DeleteFile(server string, fileId string) error {
|
2013-08-14 15:31:02 +08:00
|
|
|
fid, parseErr := storage.ParseFileId(fileId)
|
|
|
|
if parseErr != nil {
|
|
|
|
return parseErr
|
|
|
|
}
|
2013-09-02 14:58:21 +08:00
|
|
|
lookup, lookupError := Lookup(server, fid.VolumeId)
|
2013-08-14 15:31:02 +08:00
|
|
|
if lookupError != nil {
|
2013-09-02 14:58:21 +08:00
|
|
|
return lookupError
|
2013-08-14 15:31:02 +08:00
|
|
|
}
|
|
|
|
if len(lookup.Locations) == 0 {
|
2013-09-02 14:58:21 +08:00
|
|
|
return nil
|
2013-08-14 15:31:02 +08:00
|
|
|
}
|
2013-09-02 14:58:21 +08:00
|
|
|
return Delete("http://" + lookup.Locations[0].PublicUrl + "/" + fileId)
|
2013-08-14 15:31:02 +08:00
|
|
|
}
|
2012-09-26 18:27:10 +08:00
|
|
|
func Delete(url string) error {
|
|
|
|
req, err := http.NewRequest("DELETE", url, nil)
|
|
|
|
if err != nil {
|
2013-08-09 14:57:22 +08:00
|
|
|
glog.V(0).Infoln("failing to delete", url)
|
2012-09-26 18:27:10 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = http.DefaultClient.Do(req)
|
|
|
|
return err
|
|
|
|
}
|