Skip to content

Commit a3f9c40

Browse files
committed
resolve a symlink
Current implementation does not consider the case where the target executable is run via symlink. If the executable is a symlink, it should replace the linked executable file, not the symlink itself.
1 parent 8152e7e commit a3f9c40

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

apply.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,17 @@ func (o *Options) SetPublicKeyPEM(pembytes []byte) error {
269269

270270
func (o *Options) getPath() (string, error) {
271271
if o.TargetPath == "" {
272-
return osext.Executable()
272+
exe, err := osext.Executable()
273+
if err != nil {
274+
return "", err
275+
}
276+
277+
exe, err = filepath.EvalSymlinks(exe)
278+
if err != nil {
279+
return "", err
280+
}
281+
282+
return exe, nil
273283
} else {
274284
return o.TargetPath, nil
275285
}

0 commit comments

Comments
 (0)