Fix filer.backup local sink to propagate file mode changes (#4896)

This commit is contained in:
Andrew Garrett 2023-10-06 23:40:20 +11:00 committed by GitHub
parent 0fd7222d65
commit 082f67bfe9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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