mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
fuse mount: avoid lookup nil entry
fix https://github.com/chrislusf/seaweedfs/issues/1221
This commit is contained in:
parent
936e7cdbfb
commit
8645283a7b
|
@ -102,9 +102,9 @@ func GetEntry(filerClient FilerClient, fullFilePath FullPath) (entry *filer_pb.E
|
||||||
}
|
}
|
||||||
|
|
||||||
// glog.V(3).Infof("read %s request: %v", fullFilePath, request)
|
// glog.V(3).Infof("read %s request: %v", fullFilePath, request)
|
||||||
resp, err := client.LookupDirectoryEntry(context.Background(), request)
|
resp, err := filer_pb.LookupEntry(client, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == ErrNotFound || strings.Contains(err.Error(), ErrNotFound.Error()) {
|
if err == ErrNotFound {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
glog.V(3).Infof("read %s %v: %v", fullFilePath, resp, err)
|
glog.V(3).Infof("read %s %v: %v", fullFilePath, resp, err)
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
package filesys
|
package filesys
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/filer2"
|
"github.com/chrislusf/seaweedfs/weed/filer2"
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||||
|
@ -124,9 +121,9 @@ func (wfs *WFS) maybeLoadEntry(dir, name string) (entry *filer_pb.Entry, err err
|
||||||
Directory: dir,
|
Directory: dir,
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.LookupDirectoryEntry(context.Background(), request)
|
resp, err := filer_pb.LookupEntry(client, request)
|
||||||
if err != nil || resp == nil || resp.Entry == nil {
|
if err != nil {
|
||||||
if err == filer2.ErrNotFound || strings.Contains(err.Error(), filer2.ErrNotFound.Error()) {
|
if err == filer2.ErrNotFound {
|
||||||
glog.V(3).Infof("file attr read not found file %v: %v", request, err)
|
glog.V(3).Infof("file attr read not found file %v: %v", request, err)
|
||||||
return fuse.ENOENT
|
return fuse.ENOENT
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@ package filer_pb
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/filer2"
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
||||||
)
|
)
|
||||||
|
@ -84,3 +86,25 @@ func CreateEntry(client SeaweedFilerClient, request *CreateEntryRequest) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func LookupEntry(client SeaweedFilerClient, request *LookupDirectoryEntryRequest) (*LookupDirectoryEntryResponse, error) {
|
||||||
|
resp, err := filer_pb.LookupEntry(client, request)
|
||||||
|
if err != nil {
|
||||||
|
if err == filer2.ErrNotFound || strings.Contains(err.Error(), ErrNotFound.Error()) {
|
||||||
|
return nil, filer2.ErrNotFound
|
||||||
|
}
|
||||||
|
glog.V(3).Infof("read %s/%v: %v", request.Directory, request.Entry.Name, err)
|
||||||
|
return nil, fmt.Errorf("LookupEntry1: %v", err)
|
||||||
|
}
|
||||||
|
if resp.Error != "" && strings.Contains(resp.Error, ErrNotFound.Error()) {
|
||||||
|
return nil, filer2.ErrNotFound
|
||||||
|
}
|
||||||
|
if resp.Error != "" {
|
||||||
|
glog.V(3).Infof("lookup %s/%v: %v", request.Directory, request.Entry.Name, err)
|
||||||
|
return nil, fmt.Errorf("LookupEntry2: %v", err)
|
||||||
|
}
|
||||||
|
if resp.Entry == nil {
|
||||||
|
return nil, filer2.ErrNotFound
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ func (fs *FilerSink) CreateEntry(key string, entry *filer_pb.Entry) error {
|
||||||
Name: name,
|
Name: name,
|
||||||
}
|
}
|
||||||
glog.V(1).Infof("lookup: %v", lookupRequest)
|
glog.V(1).Infof("lookup: %v", lookupRequest)
|
||||||
if resp, err := client.LookupDirectoryEntry(context.Background(), lookupRequest); err == nil && resp.Entry != nil {
|
if resp, err := filer_pb.LookupEntry(client, lookupRequest); err == nil {
|
||||||
if filer2.ETag(resp.Entry.Chunks) == filer2.ETag(entry.Chunks) {
|
if filer2.ETag(resp.Entry.Chunks) == filer2.ETag(entry.Chunks) {
|
||||||
glog.V(0).Infof("already replicated %s", key)
|
glog.V(0).Infof("already replicated %s", key)
|
||||||
return nil
|
return nil
|
||||||
|
@ -148,14 +148,11 @@ func (fs *FilerSink) UpdateEntry(key string, oldEntry *filer_pb.Entry, newParent
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(4).Infof("lookup entry: %v", request)
|
glog.V(4).Infof("lookup entry: %v", request)
|
||||||
resp, err := client.LookupDirectoryEntry(context.Background(), request)
|
resp, err := filer_pb.LookupEntry(client, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(0).Infof("lookup %s: %v", key, err)
|
glog.V(0).Infof("lookup %s: %v", key, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if resp.Entry == nil {
|
|
||||||
return filer2.ErrNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
existingEntry = resp.Entry
|
existingEntry = resp.Entry
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/filer2"
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||||
)
|
)
|
||||||
|
@ -202,15 +203,15 @@ func (s3a *S3ApiServer) exists(parentDirectoryPath string, entryName string, isD
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(4).Infof("exists entry %v/%v: %v", parentDirectoryPath, entryName, request)
|
glog.V(4).Infof("exists entry %v/%v: %v", parentDirectoryPath, entryName, request)
|
||||||
resp, err := client.LookupDirectoryEntry(context.Background(), request)
|
resp, err := filer_pb.LookupEntry(client, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err == filer2.ErrNotFound {
|
||||||
|
exists = false
|
||||||
|
return nil
|
||||||
|
}
|
||||||
glog.V(0).Infof("exists entry %v: %v", request, err)
|
glog.V(0).Infof("exists entry %v: %v", request, err)
|
||||||
return fmt.Errorf("exists entry %s/%s: %v", parentDirectoryPath, entryName, err)
|
return fmt.Errorf("exists entry %s/%s: %v", parentDirectoryPath, entryName, err)
|
||||||
}
|
}
|
||||||
if resp.Entry == nil {
|
|
||||||
exists = false
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
exists = resp.Entry.IsDirectory == isDirectory
|
exists = resp.Entry.IsDirectory == isDirectory
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/aws/aws-sdk-go/service/s3"
|
"github.com/aws/aws-sdk-go/service/s3"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/filer2"
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||||
)
|
)
|
||||||
|
@ -117,7 +118,10 @@ func (s3a *S3ApiServer) HeadBucketHandler(w http.ResponseWriter, r *http.Request
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(1).Infof("lookup bucket: %v", request)
|
glog.V(1).Infof("lookup bucket: %v", request)
|
||||||
if resp, err := client.LookupDirectoryEntry(context.Background(), request); err != nil || resp.Entry == nil {
|
if _, err := filer_pb.LookupEntry(client, request); err != nil {
|
||||||
|
if err == filer2.ErrNotFound {
|
||||||
|
return filer2.ErrNotFound
|
||||||
|
}
|
||||||
return fmt.Errorf("lookup bucket %s/%s: %v", s3a.option.BucketsPath, bucket, err)
|
return fmt.Errorf("lookup bucket %s/%s: %v", s3a.option.BucketsPath, bucket, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package shell
|
package shell
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
@ -50,13 +49,10 @@ func (c *commandFsCat) Do(args []string, commandEnv *CommandEnv, writer io.Write
|
||||||
Name: name,
|
Name: name,
|
||||||
Directory: dir,
|
Directory: dir,
|
||||||
}
|
}
|
||||||
respLookupEntry, err := client.LookupDirectoryEntry(context.Background(), request)
|
respLookupEntry, err := filer_pb.LookupEntry(client, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if respLookupEntry.Entry == nil {
|
|
||||||
return fmt.Errorf("file not found: %s", path)
|
|
||||||
}
|
|
||||||
|
|
||||||
return filer2.StreamContent(commandEnv.MasterClient, writer, respLookupEntry.Entry.Chunks, 0, math.MaxInt32)
|
return filer2.StreamContent(commandEnv.MasterClient, writer, respLookupEntry.Entry.Chunks, 0, math.MaxInt32)
|
||||||
|
|
||||||
|
|
|
@ -49,13 +49,10 @@ func (c *commandFsMetaCat) Do(args []string, commandEnv *CommandEnv, writer io.W
|
||||||
Name: name,
|
Name: name,
|
||||||
Directory: dir,
|
Directory: dir,
|
||||||
}
|
}
|
||||||
respLookupEntry, err := client.LookupDirectoryEntry(context.Background(), request)
|
respLookupEntry, err := filer_pb.LookupEntry(client, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if respLookupEntry.Entry == nil {
|
|
||||||
return fmt.Errorf("file not found: %s", path)
|
|
||||||
}
|
|
||||||
|
|
||||||
m := jsonpb.Marshaler{
|
m := jsonpb.Marshaler{
|
||||||
EmitDefaults: true,
|
EmitDefaults: true,
|
||||||
|
|
|
@ -58,12 +58,12 @@ func (c *commandFsMv) Do(args []string, commandEnv *CommandEnv, writer io.Writer
|
||||||
Name: destinationDir,
|
Name: destinationDir,
|
||||||
Directory: destinationName,
|
Directory: destinationName,
|
||||||
}
|
}
|
||||||
respDestinationLookupEntry, err := client.LookupDirectoryEntry(context.Background(), destinationRequest)
|
respDestinationLookupEntry, err := filer_pb.LookupEntry(client, destinationRequest)
|
||||||
|
|
||||||
var targetDir, targetName string
|
var targetDir, targetName string
|
||||||
|
|
||||||
// moving a file or folder
|
// moving a file or folder
|
||||||
if err == nil && respDestinationLookupEntry.Entry != nil && respDestinationLookupEntry.Entry.IsDirectory {
|
if err == nil && respDestinationLookupEntry.Entry.IsDirectory {
|
||||||
// to a directory
|
// to a directory
|
||||||
targetDir = filepath.ToSlash(filepath.Join(destinationDir, destinationName))
|
targetDir = filepath.ToSlash(filepath.Join(destinationDir, destinationName))
|
||||||
targetName = sourceName
|
targetName = sourceName
|
||||||
|
|
|
@ -71,7 +71,7 @@ func (ce *CommandEnv) checkDirectory(filerServer string, filerPort int64, path s
|
||||||
|
|
||||||
return ce.withFilerClient(filerServer, filerPort, func(client filer_pb.SeaweedFilerClient) error {
|
return ce.withFilerClient(filerServer, filerPort, func(client filer_pb.SeaweedFilerClient) error {
|
||||||
|
|
||||||
resp, lookupErr := client.LookupDirectoryEntry(context.Background(), &filer_pb.LookupDirectoryEntryRequest{
|
resp, lookupErr := filer_pb.LookupEntry(client, &filer_pb.LookupDirectoryEntryRequest{
|
||||||
Directory: dir,
|
Directory: dir,
|
||||||
Name: name,
|
Name: name,
|
||||||
})
|
})
|
||||||
|
@ -79,10 +79,6 @@ func (ce *CommandEnv) checkDirectory(filerServer string, filerPort int64, path s
|
||||||
return lookupErr
|
return lookupErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.Entry == nil {
|
|
||||||
return fmt.Errorf("entry not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !resp.Entry.IsDirectory {
|
if !resp.Entry.IsDirectory {
|
||||||
return fmt.Errorf("not a directory")
|
return fmt.Errorf("not a directory")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue