From ee6335fa47dd81053c9e4ea5deb2b211c835276d Mon Sep 17 00:00:00 2001 From: wweir Date: Mon, 23 Mar 2020 07:18:15 +0800 Subject: [PATCH] Keep file mod for config file --- conf/conf.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/conf/conf.go b/conf/conf.go index 07a48af..df0447e 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -138,6 +138,16 @@ func flushConfDaemon() { } f.Close() + if stat, err := os.Stat(Conf.file); err != nil { + log.Warnw("get file stat", "file", Conf.file, "err", err) + } else { + // There is no common way to transfer ownership for a file + // cross-platform. Drop the ownership support but file mod. + if err = os.Chmod(Conf.file+"~", stat.Mode()); err != nil { + log.Warnw("set file mod", "file", Conf.file+"~", "err", err) + } + } + if err = os.Rename(Conf.file+"~", Conf.file); err != nil { log.Errorw("flush config", "step", "flush", "err", err) continue