From 082f67bfe95b3914a12669e6f9d1e934b602deb1 Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Fri, 6 Oct 2023 23:40:20 +1100 Subject: [PATCH] Fix filer.backup local sink to propagate file mode changes (#4896) --- weed/replication/sink/localsink/local_sink.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/weed/replication/sink/localsink/local_sink.go b/weed/replication/sink/localsink/local_sink.go index 134d3985a..c6dddb80a 100644 --- a/weed/replication/sink/localsink/local_sink.go +++ b/weed/replication/sink/localsink/local_sink.go @@ -90,12 +90,24 @@ func (localsink *LocalSink) CreateEntry(key string, entry *filer_pb.Entry, signa return os.Mkdir(key, os.FileMode(entry.Attributes.FileMode)) } - dstFile, err := os.OpenFile(util.ToShortFileName(key), os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.FileMode(entry.Attributes.FileMode)) + mode := os.FileMode(entry.Attributes.FileMode) + dstFile, err := os.OpenFile(util.ToShortFileName(key), os.O_RDWR|os.O_CREATE|os.O_TRUNC, mode) if err != nil { return err } defer dstFile.Close() + fi, err := dstFile.Stat() + if err != nil { + return err + } + if fi.Mode() != mode { + glog.V(4).Infof("Modify file mode: %o -> %o", fi.Mode(), mode) + if err := dstFile.Chmod(mode); err != nil { + return err + } + } + writeFunc := func(data []byte) error { _, writeErr := dstFile.Write(data) return writeErr