mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-15 20:06:19 +08:00
easier for client to delete file
This commit is contained in:
@@ -2,9 +2,24 @@ package operation
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"code.google.com/p/weed-fs/go/glog"
|
"code.google.com/p/weed-fs/go/glog"
|
||||||
|
"code.google.com/p/weed-fs/go/storage"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func DeleteFile(server string, fileId string) (error) {
|
||||||
|
fid, parseErr := storage.ParseFileId(fileId)
|
||||||
|
if parseErr != nil {
|
||||||
|
return parseErr
|
||||||
|
}
|
||||||
|
lookup, lookupError := Lookup(server,fid.VolumeId)
|
||||||
|
if lookupError != nil {
|
||||||
|
return lookupError
|
||||||
|
}
|
||||||
|
if len(lookup.Locations) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return Delete("http://"+lookup.Locations[0].PublicUrl+"/"+fileId)
|
||||||
|
}
|
||||||
func Delete(url string) error {
|
func Delete(url string) error {
|
||||||
req, err := http.NewRequest("DELETE", url, nil)
|
req, err := http.NewRequest("DELETE", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.google.com/p/weed-fs/go/glog"
|
||||||
"code.google.com/p/weed-fs/go/util"
|
"code.google.com/p/weed-fs/go/util"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
"code.google.com/p/weed-fs/go/glog"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type FileId struct {
|
type FileId struct {
|
||||||
@@ -16,16 +17,16 @@ type FileId struct {
|
|||||||
func NewFileId(VolumeId VolumeId, Key uint64, Hashcode uint32) *FileId {
|
func NewFileId(VolumeId VolumeId, Key uint64, Hashcode uint32) *FileId {
|
||||||
return &FileId{VolumeId: VolumeId, Key: Key, Hashcode: Hashcode}
|
return &FileId{VolumeId: VolumeId, Key: Key, Hashcode: Hashcode}
|
||||||
}
|
}
|
||||||
func ParseFileId(fid string) *FileId {
|
func ParseFileId(fid string) (*FileId, error) {
|
||||||
a := strings.Split(fid, ",")
|
a := strings.Split(fid, ",")
|
||||||
if len(a) != 2 {
|
if len(a) != 2 {
|
||||||
glog.V(1).Infoln("Invalid fid", fid, ", split length", len(a))
|
glog.V(1).Infoln("Invalid fid ", fid, ", split length ", len(a))
|
||||||
return nil
|
return nil, errors.New("Invalid fid " + fid)
|
||||||
}
|
}
|
||||||
vid_string, key_hash_string := a[0], a[1]
|
vid_string, key_hash_string := a[0], a[1]
|
||||||
volumeId, _ := NewVolumeId(vid_string)
|
volumeId, _ := NewVolumeId(vid_string)
|
||||||
key, hash := ParseKeyHash(key_hash_string)
|
key, hash := ParseKeyHash(key_hash_string)
|
||||||
return &FileId{VolumeId: volumeId, Key: key, Hashcode: hash}
|
return &FileId{VolumeId: volumeId, Key: key, Hashcode: hash}, nil
|
||||||
}
|
}
|
||||||
func (n *FileId) String() string {
|
func (n *FileId) String() string {
|
||||||
bytes := make([]byte, 12)
|
bytes := make([]byte, 12)
|
||||||
|
@@ -3,7 +3,6 @@ package storage
|
|||||||
import (
|
import (
|
||||||
"code.google.com/p/weed-fs/go/util"
|
"code.google.com/p/weed-fs/go/util"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"code.google.com/p/weed-fs/go/glog"
|
"code.google.com/p/weed-fs/go/glog"
|
||||||
"mime"
|
"mime"
|
||||||
@@ -54,10 +53,8 @@ func ParseUpload(r *http.Request) (fileName string, data []byte, mimeType string
|
|||||||
fileName = part.FileName()
|
fileName = part.FileName()
|
||||||
if fileName != "" {
|
if fileName != "" {
|
||||||
fileName = path.Base(fileName)
|
fileName = path.Base(fileName)
|
||||||
} else {
|
|
||||||
e = errors.New("No file found!")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data, e = ioutil.ReadAll(part)
|
data, e = ioutil.ReadAll(part)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
glog.V(0).Infoln("Reading Content [ERROR]", e)
|
glog.V(0).Infoln("Reading Content [ERROR]", e)
|
||||||
|
Reference in New Issue
Block a user