webdav: fix directory renaming

This commit is contained in:
Chris Lu 2019-05-03 14:12:51 -07:00
parent bfbecd7253
commit f0f981e7c8
3 changed files with 19 additions and 7 deletions

View file

@ -106,7 +106,7 @@ func GetEntry(ctx context.Context, filerClient FilerClient, fullFilePath string)
resp, err := client.LookupDirectoryEntry(ctx, request) resp, err := client.LookupDirectoryEntry(ctx, request)
if err != nil { if err != nil {
if err == ErrNotFound || strings.Contains(err.Error(), ErrNotFound.Error()) { if err == ErrNotFound || strings.Contains(err.Error(), ErrNotFound.Error()) {
return ErrNotFound return nil
} }
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

@ -11,6 +11,8 @@ import (
func (fs *FilerServer) AtomicRenameEntry(ctx context.Context, req *filer_pb.AtomicRenameEntryRequest) (*filer_pb.AtomicRenameEntryResponse, error) { func (fs *FilerServer) AtomicRenameEntry(ctx context.Context, req *filer_pb.AtomicRenameEntryRequest) (*filer_pb.AtomicRenameEntryResponse, error) {
glog.V(1).Infof("AtomicRenameEntry %v", req)
ctx, err := fs.filer.BeginTransaction(ctx) ctx, err := fs.filer.BeginTransaction(ctx)
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -323,9 +323,13 @@ func (fs *WebDavFileSystem) Rename(ctx context.Context, oldName, newName string)
if err != nil { if err != nil {
return os.ErrExist return os.ErrExist
} }
if of.IsDir() && !strings.HasSuffix(oldName, "/") { if of.IsDir() {
oldName += "/" if strings.HasSuffix(oldName, "/") {
newName += "/" oldName = strings.TrimRight(oldName, "/")
}
if strings.HasSuffix(newName, "/") {
newName = strings.TrimRight(newName, "/")
}
} }
_, err = fs.stat(ctx, newName) _, err = fs.stat(ctx, newName)
@ -363,10 +367,10 @@ 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 entry == nil {
if err == filer2.ErrNotFound {
return nil, os.ErrNotExist return nil, os.ErrNotExist
} }
if err != nil {
return nil, err return nil, err
} }
fi.size = int64(filer2.TotalSize(entry.GetChunks())) fi.size = int64(filer2.TotalSize(entry.GetChunks()))
@ -401,6 +405,9 @@ func (f *WebDavFile) Write(buf []byte) (int, error) {
f.entry, err = filer2.GetEntry(ctx, f.fs, f.name) f.entry, err = filer2.GetEntry(ctx, f.fs, f.name)
} }
if f.entry == nil {
return 0, err
}
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -493,6 +500,9 @@ func (f *WebDavFile) Read(p []byte) (readSize int, err error) {
if f.entry == nil { if f.entry == nil {
f.entry, err = filer2.GetEntry(ctx, f.fs, f.name) f.entry, err = filer2.GetEntry(ctx, f.fs, f.name)
} }
if f.entry == nil {
return 0, err
}
if err != nil { if err != nil {
return 0, err return 0, err
} }