diff --git a/weed/filer2/filer_client_util.go b/weed/filer2/filer_client_util.go index 829c652da..0986a54cd 100644 --- a/weed/filer2/filer_client_util.go +++ b/weed/filer2/filer_client_util.go @@ -105,8 +105,8 @@ func GetEntry(ctx context.Context, filerClient FilerClient, fullFilePath string) glog.V(3).Infof("read %s request: %v", fullFilePath, request) resp, err := client.LookupDirectoryEntry(ctx, request) if err != nil { - if err == ErrNotFound { - return nil + if err == ErrNotFound || strings.Contains(err.Error(), ErrNotFound.Error()) { + return ErrNotFound } glog.V(3).Infof("read %s attr %v: %v", fullFilePath, request, err) return err diff --git a/weed/server/webdav_server.go b/weed/server/webdav_server.go index c9e897c83..13ec88d4a 100644 --- a/weed/server/webdav_server.go +++ b/weed/server/webdav_server.go @@ -161,42 +161,30 @@ func (fs *WebDavFileSystem) Mkdir(ctx context.Context, fullDirPath string, perm return os.ErrExist } - base := "/" - for _, elem := range strings.Split(strings.Trim(fullDirPath, "/"), "/") { - base += elem + "/" - _, err = fs.stat(ctx, base) - if err != os.ErrNotExist { - return err - } - err = fs.WithFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error { - dir, name := filer2.FullPath(base).DirAndName() - request := &filer_pb.CreateEntryRequest{ - Directory: dir, - Entry: &filer_pb.Entry{ - Name: name, - IsDirectory: true, - Attributes: &filer_pb.FuseAttributes{ - Mtime: time.Now().Unix(), - Crtime: time.Now().Unix(), - FileMode: uint32(perm), - Uid: fs.option.Uid, - Gid: fs.option.Gid, - }, + return fs.WithFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error { + dir, name := filer2.FullPath(fullDirPath).DirAndName() + request := &filer_pb.CreateEntryRequest{ + Directory: dir, + Entry: &filer_pb.Entry{ + Name: name, + IsDirectory: true, + Attributes: &filer_pb.FuseAttributes{ + Mtime: time.Now().Unix(), + Crtime: time.Now().Unix(), + FileMode: uint32(perm | os.ModeDir), + Uid: fs.option.Uid, + Gid: fs.option.Gid, }, - } - - glog.V(1).Infof("mkdir: %v", request) - if _, err := client.CreateEntry(ctx, request); err != nil { - return fmt.Errorf("mkdir %s/%s: %v", dir, name, err) - } + }, + } - return nil - }) - if err != nil { - return err + glog.V(1).Infof("mkdir: %v", request) + if _, err := client.CreateEntry(ctx, request); err != nil { + return fmt.Errorf("mkdir %s/%s: %v", dir, name, err) } - } - return nil + + return nil + }) } func (fs *WebDavFileSystem) OpenFile(ctx context.Context, fullFilePath string, flag int, perm os.FileMode) (webdav.File, error) { @@ -376,6 +364,9 @@ func (fs *WebDavFileSystem) stat(ctx context.Context, fullFilePath string) (os.F var fi FileInfo entry, err := filer2.GetEntry(ctx, fs, fullFilePath) if err != nil { + if err == filer2.ErrNotFound { + return nil, os.ErrNotExist + } return nil, err } fi.size = int64(filer2.TotalSize(entry.GetChunks())) @@ -476,7 +467,7 @@ func (f *WebDavFile) Write(buf []byte) (int, error) { return nil }) - if err !=nil { + if err != nil { f.off += int64(len(buf)) } return len(buf), err @@ -552,7 +543,6 @@ func (f *WebDavFile) Readdir(count int) (ret []os.FileInfo, err error) { ret = append(ret, &fi) }) - old := f.off if old >= int64(len(ret)) { if count > 0 {