fix directory lookup nil

This commit is contained in:
Chris Lu 2020-02-25 11:13:06 -08:00
parent e86da5a491
commit 7d10fdf737
8 changed files with 22 additions and 8 deletions

View file

@ -64,9 +64,6 @@ func (f *Filer) doBatchDeleteFolderMetaAndData(ctx context.Context, entry *Entry
}
if lastFileName == "" && !isRecursive && len(entries) > 0 {
// only for first iteration in the loop
for _, child := range entries {
println("existing children", child.Name())
}
return nil, fmt.Errorf("fail to delete non-empty folder: %s", entry.FullPath)
}

View file

@ -229,7 +229,7 @@ func (dir *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.
return node, nil
}
glog.V(1).Infof("not found dir GetEntry %s: %v", fullFilePath, err)
glog.V(4).Infof("not found dir GetEntry %s: %v", fullFilePath, err)
return nil, fuse.ENOENT
}
@ -276,6 +276,9 @@ func (dir *Dir) removeOneFile(ctx context.Context, req *fuse.RemoveRequest) erro
if err != nil {
return err
}
if entry == nil {
return nil
}
dir.wfs.deleteFileChunks(ctx, entry.Chunks)

View file

@ -98,7 +98,7 @@ func (fs *FilerSink) CreateEntry(ctx context.Context, key string, entry *filer_p
Name: name,
}
glog.V(1).Infof("lookup: %v", lookupRequest)
if resp, err := client.LookupDirectoryEntry(ctx, lookupRequest); err == nil {
if resp, err := client.LookupDirectoryEntry(ctx, lookupRequest); err == nil && resp.Entry != nil {
if filer2.ETag(resp.Entry.Chunks) == filer2.ETag(entry.Chunks) {
glog.V(0).Infof("already replicated %s", key)
return nil
@ -153,6 +153,9 @@ func (fs *FilerSink) UpdateEntry(ctx context.Context, key string, oldEntry *file
glog.V(0).Infof("lookup %s: %v", key, err)
return err
}
if resp.Entry == nil {
return filer2.ErrNotFound
}
existingEntry = resp.Entry

View file

@ -154,6 +154,10 @@ func (s3a *S3ApiServer) exists(ctx context.Context, parentDirectoryPath string,
glog.V(0).Infof("exists entry %v: %v", request, 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

View file

@ -11,9 +11,10 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/gorilla/mux"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/gorilla/mux"
)
var (
@ -119,7 +120,7 @@ func (s3a *S3ApiServer) HeadBucketHandler(w http.ResponseWriter, r *http.Request
}
glog.V(1).Infof("lookup bucket: %v", request)
if _, err := client.LookupDirectoryEntry(ctx, request); err != nil {
if resp, err := client.LookupDirectoryEntry(ctx, request); err != nil || resp.Entry == nil {
return fmt.Errorf("lookup bucket %s/%s: %v", s3a.option.BucketsPath, bucket, err)
}

View file

@ -56,6 +56,9 @@ func (c *commandFsCat) Do(args []string, commandEnv *CommandEnv, writer io.Write
if err != nil {
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)

View file

@ -55,6 +55,9 @@ func (c *commandFsMetaCat) Do(args []string, commandEnv *CommandEnv, writer io.W
if err != nil {
return err
}
if respLookupEntry.Entry == nil {
return fmt.Errorf("file not found: %s", path)
}
m := jsonpb.Marshaler{
EmitDefaults: true,

View file

@ -65,7 +65,7 @@ func (c *commandFsMv) Do(args []string, commandEnv *CommandEnv, writer io.Writer
var targetDir, targetName string
// moving a file or folder
if err == nil && respDestinationLookupEntry.Entry.IsDirectory {
if err == nil && respDestinationLookupEntry.Entry!= nil && respDestinationLookupEntry.Entry.IsDirectory {
// to a directory
targetDir = filepath.ToSlash(filepath.Join(destinationDir, destinationName))
targetName = sourceName