diff options
author | Mohammed Al Sahaf <[email protected]> | 2023-10-14 00:19:22 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2023-10-13 17:19:22 -0400 |
commit | d70608b65612ccf1e61ef4d7e4686ec2d6d9891f (patch) | |
tree | 58b5005692e3b5b60621901e42e95705f7d53522 /cmd/packagesfuncs.go | |
parent | 1f60328e1740143f76bdee598281ebce8c4c8e3f (diff) | |
download | caddy-d70608b65612ccf1e61ef4d7e4686ec2d6d9891f.tar.gz caddy-d70608b65612ccf1e61ef4d7e4686ec2d6d9891f.zip |
cmd: upgrade: resolve symlink of the executable (#5891)
Diffstat (limited to 'cmd/packagesfuncs.go')
-rw-r--r-- | cmd/packagesfuncs.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/cmd/packagesfuncs.go b/cmd/packagesfuncs.go index 5d77e4d54..0784f7ee6 100644 --- a/cmd/packagesfuncs.go +++ b/cmd/packagesfuncs.go @@ -22,6 +22,7 @@ import ( "net/url" "os" "os/exec" + "path/filepath" "reflect" "runtime" "runtime/debug" @@ -103,6 +104,15 @@ func upgradeBuild(pluginPkgs map[string]struct{}, fl Flags) (int, error) { if err != nil { return caddy.ExitCodeFailedStartup, fmt.Errorf("retrieving current executable permission bits: %v", err) } + if thisExecStat.Mode()&os.ModeSymlink == os.ModeSymlink { + symSource := thisExecPath + // we are a symlink; resolve it + thisExecPath, err = filepath.EvalSymlinks(thisExecPath) + if err != nil { + return caddy.ExitCodeFailedStartup, fmt.Errorf("resolving current executable symlink: %v", err) + } + l.Info("this executable is a symlink", zap.String("source", symSource), zap.String("target", thisExecPath)) + } l.Info("this executable will be replaced", zap.String("path", thisExecPath)) // build the request URL to download this custom build |