From a3f9c4009a959d4301b250c6c740c429ae2a40dc Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 4 Jan 2018 00:00:41 +0900 Subject: [PATCH] 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. --- apply.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/apply.go b/apply.go index b26dae1..c5f978c 100644 --- a/apply.go +++ b/apply.go @@ -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 }