mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
adding exception handling for this case
This commit is contained in:
parent
f5a8382933
commit
084e0ab7bb
|
@ -19,7 +19,7 @@ type Needle struct {
|
||||||
Id uint64 "needle id"
|
Id uint64 "needle id"
|
||||||
Size uint32 "Data size"
|
Size uint32 "Data size"
|
||||||
Data []byte "The actual file data"
|
Data []byte "The actual file data"
|
||||||
Checksum CRC "CRC32 to check integrity"
|
Checksum CRC "CRC32 to check integrity"
|
||||||
Padding []byte "Aligned to 8 bytes"
|
Padding []byte "Aligned to 8 bytes"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,12 @@ func NewNeedle(r *http.Request) (n *Needle, fname string, e error) {
|
||||||
e = fe
|
e = fe
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
part, _ := form.NextPart()
|
part, fe := form.NextPart()
|
||||||
|
if fe != nil {
|
||||||
|
fmt.Println("Reading Multi part [ERROR]", fe)
|
||||||
|
e = fe
|
||||||
|
return
|
||||||
|
}
|
||||||
fname = part.FileName()
|
fname = part.FileName()
|
||||||
data, _ := ioutil.ReadAll(part)
|
data, _ := ioutil.ReadAll(part)
|
||||||
//log.Println("uploading file " + part.FileName())
|
//log.Println("uploading file " + part.FileName())
|
||||||
|
@ -99,9 +104,9 @@ func (n *Needle) Read(r io.Reader, size uint32) (int, error) {
|
||||||
n.Id = util.BytesToUint64(bytes[4:12])
|
n.Id = util.BytesToUint64(bytes[4:12])
|
||||||
n.Size = util.BytesToUint32(bytes[12:16])
|
n.Size = util.BytesToUint32(bytes[12:16])
|
||||||
n.Data = bytes[16 : 16+size]
|
n.Data = bytes[16 : 16+size]
|
||||||
checksum := util.BytesToUint32(bytes[16+size : 16+size+4])
|
checksum := util.BytesToUint32(bytes[16+size : 16+size+4])
|
||||||
if checksum != NewCRC(n.Data).Value() {
|
if checksum != NewCRC(n.Data).Value() {
|
||||||
return 0, errors.New("CRC error! Data On Disk Corrupted!")
|
return 0, errors.New("CRC error! Data On Disk Corrupted!")
|
||||||
}
|
}
|
||||||
return ret, e
|
return ret, e
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue