webdav: fix directory creation

This commit is contained in:
Chris Lu 2019-05-03 13:13:08 -07:00
parent 602d63eb4c
commit bfbecd7253
2 changed files with 28 additions and 38 deletions

View file

@ -105,8 +105,8 @@ func GetEntry(ctx context.Context, filerClient FilerClient, fullFilePath string)
glog.V(3).Infof("read %s request: %v", fullFilePath, request) glog.V(3).Infof("read %s request: %v", fullFilePath, request)
resp, err := client.LookupDirectoryEntry(ctx, request) resp, err := client.LookupDirectoryEntry(ctx, request)
if err != nil { if err != nil {
if err == ErrNotFound { if err == ErrNotFound || strings.Contains(err.Error(), ErrNotFound.Error()) {
return nil return ErrNotFound
} }
glog.V(3).Infof("read %s attr %v: %v", fullFilePath, request, err) glog.V(3).Infof("read %s attr %v: %v", fullFilePath, request, err)
return err return err

View file

@ -161,15 +161,8 @@ func (fs *WebDavFileSystem) Mkdir(ctx context.Context, fullDirPath string, perm
return os.ErrExist return os.ErrExist
} }
base := "/" return fs.WithFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error {
for _, elem := range strings.Split(strings.Trim(fullDirPath, "/"), "/") { dir, name := filer2.FullPath(fullDirPath).DirAndName()
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{ request := &filer_pb.CreateEntryRequest{
Directory: dir, Directory: dir,
Entry: &filer_pb.Entry{ Entry: &filer_pb.Entry{
@ -178,7 +171,7 @@ func (fs *WebDavFileSystem) Mkdir(ctx context.Context, fullDirPath string, perm
Attributes: &filer_pb.FuseAttributes{ Attributes: &filer_pb.FuseAttributes{
Mtime: time.Now().Unix(), Mtime: time.Now().Unix(),
Crtime: time.Now().Unix(), Crtime: time.Now().Unix(),
FileMode: uint32(perm), FileMode: uint32(perm | os.ModeDir),
Uid: fs.option.Uid, Uid: fs.option.Uid,
Gid: fs.option.Gid, Gid: fs.option.Gid,
}, },
@ -192,11 +185,6 @@ func (fs *WebDavFileSystem) Mkdir(ctx context.Context, fullDirPath string, perm
return nil return nil
}) })
if err != nil {
return err
}
}
return nil
} }
func (fs *WebDavFileSystem) OpenFile(ctx context.Context, fullFilePath string, flag int, perm os.FileMode) (webdav.File, error) { 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 var fi FileInfo
entry, err := filer2.GetEntry(ctx, fs, fullFilePath) entry, err := filer2.GetEntry(ctx, fs, fullFilePath)
if err != nil { if err != nil {
if err == filer2.ErrNotFound {
return nil, os.ErrNotExist
}
return nil, err return nil, err
} }
fi.size = int64(filer2.TotalSize(entry.GetChunks())) fi.size = int64(filer2.TotalSize(entry.GetChunks()))
@ -552,7 +543,6 @@ func (f *WebDavFile) Readdir(count int) (ret []os.FileInfo, err error) {
ret = append(ret, &fi) ret = append(ret, &fi)
}) })
old := f.off old := f.off
if old >= int64(len(ret)) { if old >= int64(len(ret)) {
if count > 0 { if count > 0 {