set filer2.ErrNotFound for not found entry

This commit is contained in:
Chris Lu 2018-07-20 02:14:18 -07:00
parent dad733086a
commit 80d80daf64
5 changed files with 21 additions and 14 deletions

View file

@ -64,7 +64,7 @@ func (store *AbstractSqlStore) FindEntry(fullpath filer2.FullPath) (*filer2.Entr
row := store.DB.QueryRow(store.SqlFind, hashToLong(dir), name, dir) row := store.DB.QueryRow(store.SqlFind, hashToLong(dir), name, dir)
var data []byte var data []byte
if err := row.Scan(&data); err != nil { if err := row.Scan(&data); err != nil {
return nil, fmt.Errorf("read entry %s: %v", fullpath, err) return nil, filer2.ErrNotFound
} }
entry := &filer2.Entry{ entry := &filer2.Entry{

View file

@ -68,7 +68,7 @@ func (store *CassandraStore) FindEntry(fullpath filer2.FullPath) (entry *filer2.
"SELECT meta FROM filemeta WHERE directory=? AND name=?", "SELECT meta FROM filemeta WHERE directory=? AND name=?",
dir, name).Consistency(gocql.One).Scan(&data); err != nil { dir, name).Consistency(gocql.One).Scan(&data); err != nil {
if err != gocql.ErrNotFound { if err != gocql.ErrNotFound {
return nil, fmt.Errorf("read entry %s: %v", fullpath, err) return nil, filer2.ErrNotFound
} }
} }

View file

@ -11,6 +11,7 @@ type FilerStore interface {
Initialize(configuration Configuration) error Initialize(configuration Configuration) error
InsertEntry(*Entry) error InsertEntry(*Entry) error
UpdateEntry(*Entry) (err error) UpdateEntry(*Entry) (err error)
// err == filer2.ErrNotFound if not found
FindEntry(FullPath) (entry *Entry, err error) FindEntry(FullPath) (entry *Entry, err error)
DeleteEntry(FullPath) (err error) DeleteEntry(FullPath) (err error)
ListDirectoryEntries(dirPath FullPath, startFileName string, includeStartFile bool, limit int) ([]*Entry, error) ListDirectoryEntries(dirPath FullPath, startFileName string, includeStartFile bool, limit int) ([]*Entry, error)

View file

@ -49,7 +49,7 @@ func (store *MemDbStore) UpdateEntry(entry *filer2.Entry) (err error) {
func (store *MemDbStore) FindEntry(fullpath filer2.FullPath) (entry *filer2.Entry, err error) { func (store *MemDbStore) FindEntry(fullpath filer2.FullPath) (entry *filer2.Entry, err error) {
item := store.tree.Get(entryItem{&filer2.Entry{FullPath: fullpath}}) item := store.tree.Get(entryItem{&filer2.Entry{FullPath: fullpath}})
if item == nil { if item == nil {
return nil, nil return nil, filer2.ErrNotFound
} }
entry = item.(entryItem).Entry entry = item.(entryItem).Entry
return entry, nil return entry, nil

View file

@ -27,10 +27,17 @@ type FilerPostResult struct {
func (fs *FilerServer) queryFileInfoByPath(w http.ResponseWriter, r *http.Request, path string) (fileId, urlLocation string, err error) { func (fs *FilerServer) queryFileInfoByPath(w http.ResponseWriter, r *http.Request, path string) (fileId, urlLocation string, err error) {
var entry *filer2.Entry var entry *filer2.Entry
if entry, err = fs.filer.FindEntry(filer2.FullPath(path)); err != nil { entry, err = fs.filer.FindEntry(filer2.FullPath(path))
if err == filer2.ErrNotFound {
return "", "", nil
}
if err != nil {
glog.V(0).Infoln("failing to find path in filer store", path, err.Error()) glog.V(0).Infoln("failing to find path in filer store", path, err.Error())
writeJsonError(w, r, http.StatusInternalServerError, err) writeJsonError(w, r, http.StatusInternalServerError, err)
} else { return
}
if len(entry.Chunks) == 0 { if len(entry.Chunks) == 0 {
glog.V(1).Infof("empty entry: %s", path) glog.V(1).Infof("empty entry: %s", path)
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
@ -42,7 +49,6 @@ func (fs *FilerServer) queryFileInfoByPath(w http.ResponseWriter, r *http.Reques
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
} }
} }
}
return return
} }