format changes

This commit is contained in:
chrislusf 2015-12-14 22:38:58 -08:00
parent df5e54e02a
commit e921cb1a9d
9 changed files with 30 additions and 34 deletions

View file

@ -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 {

View file

@ -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) {

View file

@ -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

View file

@ -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 {

View file

@ -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
}

View file

@ -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 (

View file

@ -3,11 +3,9 @@ package main
import (
"fmt"
"io"
"io/ioutil"
"os"
"path"
"io/ioutil"
"strings"
"github.com/chrislusf/seaweedfs/go/operation"

View file

@ -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 {

View file

@ -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
}