-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adopt workaround that simply hides it see https://github.com/minio/selfupdate see https://github.com/sanbornm/go-selfupdate
- Loading branch information
Showing
3 changed files
with
67 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build !windows | ||
|
||
package selfupdate | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
// swap replaces the running executable. | ||
// On most systems this simply renames the source file. | ||
func (c config) swap(source, target string) error { | ||
c.Printf("moving to %#v\n", target) | ||
return os.Rename(source, target) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package selfupdate | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
) | ||
|
||
// swap replaces the running executable. | ||
// On windows it cannot be overwritten/deleted. | ||
// It is thus renamed to an intermediate file (`{target}.old`) and simply hidden. | ||
// | ||
// see https://github.com/minio/selfupdate | ||
// see https://github.com/sanbornm/go-selfupdate | ||
func (c config) swap(source, target string) error { | ||
old := target + ".old" | ||
if _, err := os.Stat(old); err == nil { | ||
if err := c.confirm("remove %#v", old); err != nil { | ||
return err | ||
} | ||
if err := os.Remove(old); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
c.Printf("moving current executable to %#v\n", old) | ||
if err := os.Rename(target, old); err != nil { | ||
return err | ||
} | ||
|
||
c.Printf("moving new executable to %#v\n", target) | ||
if err := os.Rename(source, target); err != nil { | ||
_ = os.Rename(old, target) // try to restore old executable | ||
return err | ||
} | ||
|
||
c.Printf("hiding %#v\n", old) | ||
return hide(old) | ||
} | ||
|
||
func hide(path string) error { | ||
p, err := syscall.UTF16PtrFromString(path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = syscall.SetFileAttributes(p, syscall.FILE_ATTRIBUTE_HIDDEN) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |