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,42 +161,30 @@ 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 + "/" request := &filer_pb.CreateEntryRequest{
_, err = fs.stat(ctx, base) Directory: dir,
if err != os.ErrNotExist { Entry: &filer_pb.Entry{
return err Name: name,
} IsDirectory: true,
err = fs.WithFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error { Attributes: &filer_pb.FuseAttributes{
dir, name := filer2.FullPath(base).DirAndName() Mtime: time.Now().Unix(),
request := &filer_pb.CreateEntryRequest{ Crtime: time.Now().Unix(),
Directory: dir, FileMode: uint32(perm | os.ModeDir),
Entry: &filer_pb.Entry{ Uid: fs.option.Uid,
Name: name, Gid: fs.option.Gid,
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,
},
}, },
} },
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
} }
}
return nil 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
})
} }
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()))
@ -476,7 +467,7 @@ func (f *WebDavFile) Write(buf []byte) (int, error) {
return nil return nil
}) })
if err !=nil { if err != nil {
f.off += int64(len(buf)) f.off += int64(len(buf))
} }
return len(buf), err return len(buf), err
@ -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 {