aboutsummaryrefslogtreecommitdiff
path: root/go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2013-08-14 00:31:02 -0700
committerChris Lu <chris.lu@gmail.com>2013-08-14 00:31:02 -0700
commit48e4ced29d86d0cc2e525b727ae3fdcd3cbacf91 (patch)
treeb9190d260b1386a87a1f0356a3d519e01a476e34 /go
parentd5e7c1de0ae4667d7362b869081eeeb6085a426b (diff)
downloadseaweedfs-48e4ced29d86d0cc2e525b727ae3fdcd3cbacf91.tar.xz
seaweedfs-48e4ced29d86d0cc2e525b727ae3fdcd3cbacf91.zip
easier for client to delete file
Diffstat (limited to 'go')
-rw-r--r--go/operation/delete_content.go15
-rw-r--r--go/storage/file_id.go11
-rw-r--r--go/storage/needle.go5
3 files changed, 22 insertions, 9 deletions
diff --git a/go/operation/delete_content.go b/go/operation/delete_content.go
index 12f3ca4e8..8f8ea58f3 100644
--- a/go/operation/delete_content.go
+++ b/go/operation/delete_content.go
@@ -2,9 +2,24 @@ package operation
import (
"code.google.com/p/weed-fs/go/glog"
+ "code.google.com/p/weed-fs/go/storage"
"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 {
req, err := http.NewRequest("DELETE", url, nil)
if err != nil {
diff --git a/go/storage/file_id.go b/go/storage/file_id.go
index f482af029..344cc048b 100644
--- a/go/storage/file_id.go
+++ b/go/storage/file_id.go
@@ -1,10 +1,11 @@
package storage
import (
+ "code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/util"
"encoding/hex"
+ "errors"
"strings"
- "code.google.com/p/weed-fs/go/glog"
)
type FileId struct {
@@ -16,16 +17,16 @@ type FileId struct {
func NewFileId(VolumeId VolumeId, Key uint64, Hashcode uint32) *FileId {
return &FileId{VolumeId: VolumeId, Key: Key, Hashcode: Hashcode}
}
-func ParseFileId(fid string) *FileId {
+func ParseFileId(fid string) (*FileId, error) {
a := strings.Split(fid, ",")
if len(a) != 2 {
- glog.V(1).Infoln("Invalid fid", fid, ", split length", len(a))
- return nil
+ glog.V(1).Infoln("Invalid fid ", fid, ", split length ", len(a))
+ return nil, errors.New("Invalid fid " + fid)
}
vid_string, key_hash_string := a[0], a[1]
volumeId, _ := NewVolumeId(vid_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 {
bytes := make([]byte, 12)
diff --git a/go/storage/needle.go b/go/storage/needle.go
index 083ce6d5f..54799df4e 100644
--- a/go/storage/needle.go
+++ b/go/storage/needle.go
@@ -3,7 +3,6 @@ package storage
import (
"code.google.com/p/weed-fs/go/util"
"encoding/hex"
- "errors"
"io/ioutil"
"code.google.com/p/weed-fs/go/glog"
"mime"
@@ -54,10 +53,8 @@ func ParseUpload(r *http.Request) (fileName string, data []byte, mimeType string
fileName = part.FileName()
if fileName != "" {
fileName = path.Base(fileName)
- } else {
- e = errors.New("No file found!")
- return
}
+
data, e = ioutil.ReadAll(part)
if e != nil {
glog.V(0).Infoln("Reading Content [ERROR]", e)