Skip to content

Commit d70608b

Browse files
authored
cmd: upgrade: resolve symlink of the executable (#5891)
1 parent 1f60328 commit d70608b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

cmd/packagesfuncs.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"net/url"
2323
"os"
2424
"os/exec"
25+
"path/filepath"
2526
"reflect"
2627
"runtime"
2728
"runtime/debug"
@@ -103,6 +104,15 @@ func upgradeBuild(pluginPkgs map[string]struct{}, fl Flags) (int, error) {
103104
if err != nil {
104105
return caddy.ExitCodeFailedStartup, fmt.Errorf("retrieving current executable permission bits: %v", err)
105106
}
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+
}
106116
l.Info("this executable will be replaced", zap.String("path", thisExecPath))
107117

108118
// build the request URL to download this custom build

0 commit comments

Comments
 (0)