@@ -111,6 +111,8 @@ func Apply(update io.Reader, opts Options) error {
111
111
if err != nil {
112
112
return err
113
113
}
114
+ defer fp .Close ()
115
+
114
116
_ , err = io .Copy (fp , bytes .NewReader (newBytes ))
115
117
if err != nil {
116
118
return err
@@ -122,7 +124,8 @@ func Apply(update io.Reader, opts Options) error {
122
124
123
125
// this is where we'll move the executable to so that we can swap in the updated replacement
124
126
oldPath := opts .OldSavePath
125
- if oldPath == "" {
127
+ removeOld := opts .OldSavePath == ""
128
+ if removeOld {
126
129
oldPath = filepath .Join (updateDir , fmt .Sprintf (".%s.old" , filename ))
127
130
}
128
131
@@ -157,7 +160,7 @@ func Apply(update io.Reader, opts Options) error {
157
160
}
158
161
159
162
// move successful, remove the old binary if needed
160
- if opts . OldSavePath == "" {
163
+ if removeOld {
161
164
errRemove := os .Remove (oldPath )
162
165
163
166
// windows has trouble with removing old binaries, so hide it instead
@@ -217,8 +220,8 @@ type Options struct {
217
220
// If non-nil, treat the update contents as a patch and use this object to apply the patch.
218
221
Patcher Patcher
219
222
220
- //OldPath defines the path where the old executable is stored after update
221
- //If set to empty string old executable is removed after update(default)
223
+ // Store the old executable file at this path after a successful update.
224
+ // The empty string means the old executable file will be removed after the update.
222
225
OldSavePath string
223
226
}
224
227
0 commit comments