diff --git a/go/operation/chunked_file.go b/go/operation/chunked_file.go index 70564cbd2..786b8a989 100644 --- a/go/operation/chunked_file.go +++ b/go/operation/chunked_file.go @@ -74,7 +74,7 @@ func (cm *ChunkManifest) DeleteChunks(master string) error { for _, ci := range cm.Chunks { if e := DeleteFile(master, ci.Fid, ""); e != nil { deleteError++ - glog.V(0).Infof("Delete %s error: %s, master: %s", ci.Fid, e.Error(), master) + glog.V(0).Infof("Delete %s error: %v, master: %s", ci.Fid, e, master) } } if deleteError > 0 { diff --git a/go/operation/delete_content.go b/go/operation/delete_content.go index 32ad69b17..c808cc75a 100644 --- a/go/operation/delete_content.go +++ b/go/operation/delete_content.go @@ -3,6 +3,7 @@ package operation import ( "encoding/json" "errors" + "fmt" "net/url" "strings" "sync" @@ -23,9 +24,13 @@ type DeleteResult struct { func DeleteFile(master string, fileId string, jwt security.EncodedJwt) error { fileUrl, err := LookupFileId(master, fileId) if err != nil { - return err + return fmt.Errorf("Failed to lookup %s:%v", fileId, err) } - return util.Delete(fileUrl, jwt) + err = util.Delete(fileUrl, jwt) + if err != nil { + return fmt.Errorf("Failed to delete %s:%v", fileUrl, err) + } + return nil } func ParseFileId(fid string) (vid string, key_cookie string, err error) { diff --git a/go/operation/submit.go b/go/operation/submit.go index d996d63f0..18484680a 100644 --- a/go/operation/submit.go +++ b/go/operation/submit.go @@ -4,13 +4,12 @@ import ( "bytes" "io" "mime" + "net/url" "os" "path" "strconv" "strings" - "net/url" - "github.com/chrislusf/seaweedfs/go/glog" "github.com/chrislusf/seaweedfs/go/security" ) @@ -188,7 +187,7 @@ func upload_chunked_file_manifest(fileUrl string, manifest *ChunkManifest, jwt s glog.V(4).Info("Uploading chunks manifest ", manifest.Name, " to ", fileUrl, "...") u, _ := url.Parse(fileUrl) q := u.Query() - q.Set("cm", "1") + q.Set("cm", "true") u.RawQuery = q.Encode() _, e = Upload(u.String(), manifest.Name, bufReader, false, "application/json", jwt) return e diff --git a/go/storage/needle.go b/go/storage/needle.go index 32ebdae7d..e49368820 100644 --- a/go/storage/needle.go +++ b/go/storage/needle.go @@ -14,8 +14,8 @@ import ( "github.com/chrislusf/seaweedfs/go/glog" "github.com/chrislusf/seaweedfs/go/images" - "github.com/chrislusf/seaweedfs/go/util" "github.com/chrislusf/seaweedfs/go/operation" + "github.com/chrislusf/seaweedfs/go/util" ) const ( @@ -53,7 +53,9 @@ func (n *Needle) String() (str string) { return } -func ParseUpload(r *http.Request) (fileName string, data []byte, mimeType string, isGzipped bool, modifiedTime uint64, ttl *TTL, isChunkedFile bool, e error) { +func ParseUpload(r *http.Request) ( + fileName string, data []byte, mimeType string, isGzipped bool, + modifiedTime uint64, ttl *TTL, isChunkedFile bool, e error) { form, fe := r.MultipartReader() if fe != nil { glog.V(0).Infoln("MultipartReader [ERROR]", fe) @@ -163,7 +165,7 @@ func NewNeedle(r *http.Request, fixJpgOrientation bool) (n *Needle, e error) { } if isChunkedFile { - n.SetChunkManifest() + n.SetIsChunkManifest() } if fixJpgOrientation { diff --git a/go/storage/needle_read_write.go b/go/storage/needle_read_write.go index 9d7af600a..ccfe1d498 100644 --- a/go/storage/needle_read_write.go +++ b/go/storage/needle_read_write.go @@ -16,7 +16,7 @@ const ( FlagHasMime = 0x04 FlagHasLastModifiedDate = 0x08 FlagHasTtl = 0x10 - FlagChunkManifest = 0x80 + FlagIsChunkManifest = 0x80 LastModifiedBytesLength = 5 TtlBytesLength = 2 ) @@ -283,9 +283,9 @@ func (n *Needle) SetHasTtl() { } func (n *Needle) IsChunkedManifest() bool { - return n.Flags&FlagChunkManifest > 0 + return n.Flags&FlagIsChunkManifest > 0 } -func (n *Needle) SetChunkManifest() { - n.Flags = n.Flags | FlagChunkManifest +func (n *Needle) SetIsChunkManifest() { + n.Flags = n.Flags | FlagIsChunkManifest } diff --git a/go/util/http_util.go b/go/util/http_util.go index f80ab0c24..29b2043ee 100644 --- a/go/util/http_util.go +++ b/go/util/http_util.go @@ -2,6 +2,8 @@ package util import ( "bytes" + "encoding/json" + "errors" "fmt" "io" "io/ioutil" @@ -9,10 +11,7 @@ import ( "net/url" "strings" - "encoding/json" - "github.com/chrislusf/seaweedfs/go/security" - "github.com/syndtr/goleveldb/leveldb/errors" ) var ( diff --git a/go/weed/download.go b/go/weed/download.go index dfe4f88b4..2e948a056 100644 --- a/go/weed/download.go +++ b/go/weed/download.go @@ -3,11 +3,9 @@ package main import ( "fmt" "io" + "io/ioutil" "os" "path" - - "io/ioutil" - "strings" "github.com/chrislusf/seaweedfs/go/operation" diff --git a/go/weed/weed_server/volume_server_handlers_read.go b/go/weed/weed_server/volume_server_handlers_read.go index 2aa0fc656..bfa6d6a4f 100644 --- a/go/weed/weed_server/volume_server_handlers_read.go +++ b/go/weed/weed_server/volume_server_handlers_read.go @@ -1,18 +1,16 @@ package weed_server import ( + "bytes" "io" "mime" "mime/multipart" "net/http" + "path" "strconv" "strings" "time" - "path" - - "bytes" - "github.com/chrislusf/seaweedfs/go/glog" "github.com/chrislusf/seaweedfs/go/images" "github.com/chrislusf/seaweedfs/go/operation" @@ -135,15 +133,10 @@ func (vs *VolumeServer) tryHandleChunkedFile(n *storage.Needle, fileName string, if !n.IsChunkedManifest() { return false } - raw, _ := strconv.ParseBool(r.FormValue("raw")) - if raw { - return false - } - processed = true chunkManifest, e := operation.LoadChunkManifest(n.Data, n.IsGzipped()) if e != nil { - glog.V(0).Infof("load chunked manifest (%s) error: %s", r.URL.Path, e.Error()) + glog.V(0).Infof("load chunked manifest (%s) error: %v", r.URL.Path, e) return false } if fileName == "" && chunkManifest.Name != "" { @@ -167,7 +160,7 @@ func (vs *VolumeServer) tryHandleChunkedFile(n *storage.Needle, fileName string, if e := writeResponseContent(fileName, mType, chunkedFileReader, w, r); e != nil { glog.V(2).Infoln("response write error:", e) } - return + return true } func writeResponseContent(filename, mimeType string, rs io.ReadSeeker, w http.ResponseWriter, r *http.Request) error { diff --git a/go/weed/weed_server/volume_server_handlers_write.go b/go/weed/weed_server/volume_server_handlers_write.go index 1f0fa96dd..3d2afaf77 100644 --- a/go/weed/weed_server/volume_server_handlers_write.go +++ b/go/weed/weed_server/volume_server_handlers_write.go @@ -2,6 +2,7 @@ package weed_server import ( "errors" + "fmt" "net/http" "github.com/chrislusf/seaweedfs/go/glog" @@ -72,12 +73,12 @@ func (vs *VolumeServer) DeleteHandler(w http.ResponseWriter, r *http.Request) { if n.IsChunkedManifest() { chunkManifest, e := operation.LoadChunkManifest(n.Data, n.IsGzipped()) if e != nil { - writeJsonError(w, r, http.StatusInternalServerError, errors.New("Load chunks manifest error: "+e.Error())) + writeJsonError(w, r, http.StatusInternalServerError, fmt.Errorf("Load chunks manifest error: %v", e)) return } // make sure all chunks had deleted before delete manifest if e := chunkManifest.DeleteChunks(vs.GetMasterNode()); e != nil { - writeJsonError(w, r, http.StatusInternalServerError, errors.New("Delete chunks error: "+e.Error())) + writeJsonError(w, r, http.StatusInternalServerError, fmt.Errorf("Delete chunks error: %v", e)) return } count = chunkManifest.Size @@ -123,11 +124,10 @@ func (vs *VolumeServer) batchDeleteHandler(w http.ResponseWriter, r *http.Reques } if n.IsChunkedManifest() { - //Don't allow delete manifest in batch delete mode ret = append(ret, operation.DeleteResult{ Fid: fid, Status: http.StatusNotAcceptable, - Error: "ChunkManifest: not allow.", + Error: "ChunkManifest: not allowed in batch delete mode.", }) continue }