fix: webdav avoid create empty files (#5160)

This commit is contained in:
Konstantin Lebedev 2024-01-03 22:52:51 +05:00 committed by GitHub
parent b832ddd1ef
commit 3e43778869
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -241,7 +241,7 @@ func (fs *WebDavFileSystem) OpenFile(ctx context.Context, fullFilePath string, f
Name: name,
IsDirectory: perm&os.ModeDir > 0,
Attributes: &filer_pb.FuseAttributes{
Mtime: time.Now().Unix(),
Mtime: 0,
Crtime: time.Now().Unix(),
FileMode: uint32(perm),
Uid: fs.option.Uid,
@ -429,12 +429,13 @@ func (f *WebDavFile) Write(buf []byte) (int, error) {
glog.V(2).Infof("WebDavFileSystem.Write %v", f.name)
dir, _ := util.FullPath(f.name).DirAndName()
fullPath := util.FullPath(f.name)
dir, _ := fullPath.DirAndName()
var getErr error
ctx := context.Background()
if f.entry == nil {
f.entry, getErr = filer_pb.GetEntry(f.fs, util.FullPath(f.name))
f.entry, getErr = filer_pb.GetEntry(f.fs, fullPath)
}
if f.entry == nil {
@ -451,6 +452,11 @@ func (f *WebDavFile) Write(buf []byte) (int, error) {
chunk, flushErr = f.saveDataAsChunk(util.NewBytesReader(data), f.name, offset, time.Now().UnixNano())
if flushErr != nil {
if f.entry.Attributes.Mtime == 0 {
if err := f.fs.removeAll(ctx, f.name); err != nil {
glog.Errorf("bufWriter.Flush remove file error: %+v", f.name)
}
}
return fmt.Errorf("%s upload result: %v", f.name, flushErr)
}