Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
cmd: upgrade: inherit the permissions of the original executable (#4160)
Mohammed Al Sahaf committed
May 11, 2021 at 22:11 UTC
2aefe156869851a89d7a34e28c3e4ff3ac442fff
1 file changed
+5
-1
cmd/commandfuncs.go
+5
-1
@@ -577,6 +577,10 @@ func cmdUpgrade(_ Flags) (int, error) {
577
if err != nil {
578
return caddy.ExitCodeFailedStartup, fmt.Errorf("determining current executable path: %v", err)
579
}
580
+ thisExecStat, err := os.Stat(thisExecPath)
581
+ if err != nil {
582
+ return caddy.ExitCodeFailedStartup, fmt.Errorf("retrieving current executable permission bits: %v", err)
583
+ }
584
l.Info("this executable will be replaced", zap.String("path", thisExecPath))
585
586
// get the list of nonstandard plugins
@@ -654,7 +658,7 @@ func cmdUpgrade(_ Flags) (int, error) {
658
659
// download the file; do this in a closure to close reliably before we execute it
660
writeFile := func() error {
657
- destFile, err := os.OpenFile(thisExecPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0770)
661
+ destFile, err := os.OpenFile(thisExecPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, thisExecStat.Mode())
662
if err != nil {
663
return fmt.Errorf("unable to open destination file: %v", err)
664
}