Commit 1f2e174e authored by Kevin Atkinson's avatar Kevin Atkinson

filestore: use the same codes in ListRes and CorruptReferenceError.

License: MIT
Signed-off-by: default avatarKevin Atkinson <k@kevina.org>
parent 033c442d
......@@ -27,17 +27,8 @@ type FileManager struct {
root string
}
type CorruptReferenceCode int
const (
OtherErr CorruptReferenceCode = 0
FileError CorruptReferenceCode = 1
FileMissing CorruptReferenceCode = 2
FileChanged CorruptReferenceCode = 3
)
type CorruptReferenceError struct {
Code CorruptReferenceCode
Code Status
Err error
}
......@@ -138,23 +129,23 @@ func (f *FileManager) readDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) {
fi, err := os.Open(abspath)
if os.IsNotExist(err) {
return nil, &CorruptReferenceError{FileMissing, err}
return nil, &CorruptReferenceError{StatusFileNotFound, err}
} else if err != nil {
return nil, &CorruptReferenceError{FileError, err}
return nil, &CorruptReferenceError{StatusFileError, err}
}
defer fi.Close()
_, err = fi.Seek(int64(d.GetOffset()), os.SEEK_SET)
if err != nil {
return nil, &CorruptReferenceError{FileError, err}
return nil, &CorruptReferenceError{StatusFileError, err}
}
outbuf := make([]byte, d.GetSize_())
_, err = io.ReadFull(fi, outbuf)
if err == io.EOF || err == io.ErrUnexpectedEOF {
return nil, &CorruptReferenceError{FileChanged, err}
return nil, &CorruptReferenceError{StatusFileChanged, err}
} else if err != nil {
return nil, &CorruptReferenceError{FileError, err}
return nil, &CorruptReferenceError{StatusFileError, err}
}
outcid, err := c.Prefix().Sum(outbuf)
......@@ -163,7 +154,7 @@ func (f *FileManager) readDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) {
}
if !c.Equals(outcid) {
return nil, &CorruptReferenceError{FileChanged,
return nil, &CorruptReferenceError{StatusFileChanged,
fmt.Errorf("data in file did not match. %s offset %d", d.GetFilePath(), d.GetOffset())}
}
......
......@@ -144,16 +144,7 @@ func mkListRes(c *cid.Cid, d *pb.DataObj, err error) *ListRes {
if err == ds.ErrNotFound || err == blockstore.ErrNotFound {
status = StatusKeyNotFound
} else if err, ok := err.(*CorruptReferenceError); ok {
switch err.Code {
case FileError:
status = StatusFileError
case FileMissing:
status = StatusFileNotFound
case FileChanged:
status = StatusFileChanged
default:
status = StatusOtherError
}
status = err.Code
} else {
status = StatusOtherError
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment