From 7d10fdf73720fb3234cd5cacfaf10fb79590d754 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 25 Feb 2020 11:13:06 -0800 Subject: [PATCH] fix directory lookup nil --- weed/filer2/filer_delete_entry.go | 3 --- weed/filesys/dir.go | 5 ++++- weed/replication/sink/filersink/filer_sink.go | 5 ++++- weed/s3api/filer_util.go | 4 ++++ weed/s3api/s3api_bucket_handlers.go | 5 +++-- weed/shell/command_fs_cat.go | 3 +++ weed/shell/command_fs_meta_cat.go | 3 +++ weed/shell/command_fs_mv.go | 2 +- 8 files changed, 22 insertions(+), 8 deletions(-) diff --git a/weed/filer2/filer_delete_entry.go b/weed/filer2/filer_delete_entry.go index 2d3654df6..af88d1512 100644 --- a/weed/filer2/filer_delete_entry.go +++ b/weed/filer2/filer_delete_entry.go @@ -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) } diff --git a/weed/filesys/dir.go b/weed/filesys/dir.go index 203545b44..2a4f6fa75 100644 --- a/weed/filesys/dir.go +++ b/weed/filesys/dir.go @@ -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) diff --git a/weed/replication/sink/filersink/filer_sink.go b/weed/replication/sink/filersink/filer_sink.go index 8c4c39bc4..cdc4f4a45 100644 --- a/weed/replication/sink/filersink/filer_sink.go +++ b/weed/replication/sink/filersink/filer_sink.go @@ -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 diff --git a/weed/s3api/filer_util.go b/weed/s3api/filer_util.go index 2fceacd2a..91c34f0eb 100644 --- a/weed/s3api/filer_util.go +++ b/weed/s3api/filer_util.go @@ -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 diff --git a/weed/s3api/s3api_bucket_handlers.go b/weed/s3api/s3api_bucket_handlers.go index 492d94616..69275e212 100644 --- a/weed/s3api/s3api_bucket_handlers.go +++ b/weed/s3api/s3api_bucket_handlers.go @@ -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) } diff --git a/weed/shell/command_fs_cat.go b/weed/shell/command_fs_cat.go index 238dee7f9..06c8232c9 100644 --- a/weed/shell/command_fs_cat.go +++ b/weed/shell/command_fs_cat.go @@ -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) diff --git a/weed/shell/command_fs_meta_cat.go b/weed/shell/command_fs_meta_cat.go index 9980f67a2..ec9a495f2 100644 --- a/weed/shell/command_fs_meta_cat.go +++ b/weed/shell/command_fs_meta_cat.go @@ -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, diff --git a/weed/shell/command_fs_mv.go b/weed/shell/command_fs_mv.go index e77755921..b9301ad3c 100644 --- a/weed/shell/command_fs_mv.go +++ b/weed/shell/command_fs_mv.go @@ -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