@@ -68,6 +68,38 @@ var errHashMismatch = errors.New("new file hash mismatch after patch")
68
68
var errDiffURLUndefined = errors .New ("DiffURL is not defined, I cannot fetch and apply patch, reverting to full bin" )
69
69
var up = update .New ()
70
70
71
+ func Start (src string ) string {
72
+ // If the executable is temporary, copy it to the full path, then restart
73
+ if strings .Contains (src , "-temp" ) {
74
+ newPath := removeTempSuffixFromPath (src )
75
+ if err := copyExe (src , newPath ); err != nil {
76
+ log .Println ("Copy error: " , err )
77
+ panic (err )
78
+ }
79
+ return newPath
80
+ }
81
+
82
+ // Otherwise copy to a path with -temp suffix
83
+ if err := copyExe (src , AddTempSuffixToPath (src )); err != nil {
84
+ panic (err )
85
+ }
86
+ return ""
87
+ }
88
+
89
+ func copyExe (from , to string ) error {
90
+ data , err := os .ReadFile (from )
91
+ if err != nil {
92
+ log .Println ("Cannot read file: " , from )
93
+ return err
94
+ }
95
+ err = os .WriteFile (to , data , 0755 )
96
+ if err != nil {
97
+ log .Println ("Cannot write file: " , to )
98
+ return err
99
+ }
100
+ return nil
101
+ }
102
+
71
103
// AddTempSuffixToPath adds the "-temp" suffix to the path to an executable file (a ".exe" extension is replaced with "-temp.exe")
72
104
func AddTempSuffixToPath (path string ) string {
73
105
if filepath .Ext (path ) == "exe" {
@@ -79,8 +111,8 @@ func AddTempSuffixToPath(path string) string {
79
111
return path
80
112
}
81
113
82
- // RemoveTempSuffixFromPath removes "-temp" suffix from the path to an executable file (a "-temp.exe" extension is replaced with ".exe")
83
- func RemoveTempSuffixFromPath (path string ) string {
114
+ // removeTempSuffixFromPath removes "-temp" suffix from the path to an executable file (a "-temp.exe" extension is replaced with ".exe")
115
+ func removeTempSuffixFromPath (path string ) string {
84
116
return strings .Replace (path , "-temp" , "" , - 1 )
85
117
}
86
118
0 commit comments