Skip to content

Commit

Permalink
resolve a symlink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rhysd committed Nov 23, 2018
1 parent 8152e7e commit a3f9c40
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,17 @@ func (o *Options) SetPublicKeyPEM(pembytes []byte) error {

func (o *Options) getPath() (string, error) {
if o.TargetPath == "" {
return osext.Executable()
exe, err := osext.Executable()
if err != nil {
return "", err
}

exe, err = filepath.EvalSymlinks(exe)
if err != nil {
return "", err
}

return exe, nil
} else {
return o.TargetPath, nil
}
Expand Down

0 comments on commit a3f9c40

Please sign in to comment.