Skip to content

Commit 7a87291

Browse files
minor cleanup to complete the merge
1 parent 8eaf7cf commit 7a87291

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

apply.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ func Apply(update io.Reader, opts Options) error {
111111
if err != nil {
112112
return err
113113
}
114+
defer fp.Close()
115+
114116
_, err = io.Copy(fp, bytes.NewReader(newBytes))
115117
if err != nil {
116118
return err
@@ -122,7 +124,8 @@ func Apply(update io.Reader, opts Options) error {
122124

123125
// this is where we'll move the executable to so that we can swap in the updated replacement
124126
oldPath := opts.OldSavePath
125-
if oldPath == "" {
127+
removeOld := opts.OldSavePath == ""
128+
if removeOld {
126129
oldPath = filepath.Join(updateDir, fmt.Sprintf(".%s.old", filename))
127130
}
128131

@@ -157,7 +160,7 @@ func Apply(update io.Reader, opts Options) error {
157160
}
158161

159162
// move successful, remove the old binary if needed
160-
if opts.OldSavePath == "" {
163+
if removeOld {
161164
errRemove := os.Remove(oldPath)
162165

163166
// windows has trouble with removing old binaries, so hide it instead
@@ -217,8 +220,8 @@ type Options struct {
217220
// If non-nil, treat the update contents as a patch and use this object to apply the patch.
218221
Patcher Patcher
219222

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.
222225
OldSavePath string
223226
}
224227

apply_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestApplyOldSavePath(t *testing.T) {
7070

7171
oldfName := "OldSavePath"
7272

73-
err := Apply(bytes.NewReader(newFile), &Options{
73+
err := Apply(bytes.NewReader(newFile), Options{
7474
TargetPath: fName,
7575
OldSavePath: oldfName,
7676
})

0 commit comments

Comments
 (0)