summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorMohammed Al Sahaf <msaa1990@gmail.com>2021-05-11 22:11:27 +0000
committerGitHub <noreply@github.com>2021-05-11 16:11:27 -0600
commit2aefe156869851a89d7a34e28c3e4ff3ac442fff (patch)
tree468f7635b9ea2915a63e61151cbf90039dcfa203 /cmd
parentdbe164d98a58e8b0dbf3fed26e4e9bb6f668a9e2 (diff)
cmd: upgrade: inherit the permissions of the original executable (#4160)
Diffstat (limited to 'cmd')
-rw-r--r--cmd/commandfuncs.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/cmd/commandfuncs.go b/cmd/commandfuncs.go
index f24a9d0..58b9720 100644
--- a/cmd/commandfuncs.go
+++ b/cmd/commandfuncs.go
@@ -577,6 +577,10 @@ func cmdUpgrade(_ Flags) (int, error) {
if err != nil {
return caddy.ExitCodeFailedStartup, fmt.Errorf("determining current executable path: %v", err)
}
+ thisExecStat, err := os.Stat(thisExecPath)
+ if err != nil {
+ return caddy.ExitCodeFailedStartup, fmt.Errorf("retrieving current executable permission bits: %v", err)
+ }
l.Info("this executable will be replaced", zap.String("path", thisExecPath))
// get the list of nonstandard plugins
@@ -654,7 +658,7 @@ func cmdUpgrade(_ Flags) (int, error) {
// download the file; do this in a closure to close reliably before we execute it
writeFile := func() error {
- destFile, err := os.OpenFile(thisExecPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0770)
+ destFile, err := os.OpenFile(thisExecPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, thisExecStat.Mode())
if err != nil {
return fmt.Errorf("unable to open destination file: %v", err)
}