@marcel91200 / caddy Mirror · read-only / commits / d70608b6
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 22:00 UTC

cmd: upgrade: resolve symlink of the executable (#5891)

Mohammed Al Sahaf committed Oct 14, 2023 at 00:19 UTC d70608b65612ccf1e61ef4d7e4686ec2d6d9891f
1 file changed +10
cmd/packagesfuncs.go
+10
@@ -22,6 +22,7 @@ import (
22 "net/url"
23 "os"
24 "os/exec"
25 + "path/filepath"
26 "reflect"
27 "runtime"
28 "runtime/debug"
@@ -103,6 +104,15 @@ func upgradeBuild(pluginPkgs map[string]struct{}, fl Flags) (int, error) {
104 if err != nil {
105 return caddy.ExitCodeFailedStartup, fmt.Errorf("retrieving current executable permission bits: %v", err)
106 }
107 + if thisExecStat.Mode()&os.ModeSymlink == os.ModeSymlink {
108 + symSource := thisExecPath
109 + // we are a symlink; resolve it
110 + thisExecPath, err = filepath.EvalSymlinks(thisExecPath)
111 + if err != nil {
112 + return caddy.ExitCodeFailedStartup, fmt.Errorf("resolving current executable symlink: %v", err)
113 + }
114 + l.Info("this executable is a symlink", zap.String("source", symSource), zap.String("target", thisExecPath))
115 + }
116 l.Info("this executable will be replaced", zap.String("path", thisExecPath))
117
118 // build the request URL to download this custom build