Skip to content

Commit 9f61d4e

Browse files
committed
Defer closing file
- Now that retries have been implemented, properly deferring file closures is necessary to prevent race conditions.
1 parent d31ae88 commit 9f61d4e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

abc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func Download (urlRaw, file, byteRange, agent *string, timeout *time.Duration, r
231231
if !noProgress {os.Stdout.WriteString("\n")}
232232
os.Stdout.WriteString("Retry "+strconv.Itoa(retry)+"...\n")
233233
}
234-
oFile.Close()
234+
defer oFile.Close()
235235
err = filePrep(file)
236236
if err != nil {
237237
debug(err)
@@ -288,7 +288,7 @@ func Download (urlRaw, file, byteRange, agent *string, timeout *time.Duration, r
288288
syncProgress()
289289
if canRetry(retryMax) {
290290
defer response.Body.Close()
291-
oFile.Close()
291+
defer oFile.Close()
292292
continue
293293
}
294294
debug(err)
@@ -301,7 +301,7 @@ func Download (urlRaw, file, byteRange, agent *string, timeout *time.Duration, r
301301
if err != nil {
302302
syncProgress()
303303
if canRetry(retryMax) {
304-
oFile.Close()
304+
defer oFile.Close()
305305
continue
306306
}
307307
debug(err)

0 commit comments

Comments
 (0)