-
Notifications
You must be signed in to change notification settings - Fork 257
Remove failed decompressed files #564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ func Copy(ctx context.Context, dst io.Writer, src io.Reader) (int64, error) { | |
|
|
||
| // copyReader copies from an io.Reader into a file, using umask to create the dst file | ||
| func copyReader(dst string, src io.Reader, fmode, umask os.FileMode, fileSizeLimit int64) error { | ||
| dstF, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, fmode) | ||
| dstF, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, mode(fmode, umask)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -47,6 +47,9 @@ func copyReader(dst string, src io.Reader, fmode, umask os.FileMode, fileSizeLim | |
|
|
||
| _, err = io.Copy(dstF, src) | ||
| if err != nil { | ||
| // Close & remove the file in case of partial write | ||
| _ = dstF.Close() | ||
| _ = os.Remove(dst) | ||
| return err | ||
| } | ||
|
|
||
|
|
@@ -74,14 +77,17 @@ func copyFile(ctx context.Context, dst, src string, disableSymlinks bool, fmode, | |
| } | ||
| defer func() { _ = srcF.Close() }() | ||
|
|
||
| dstF, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, fmode) | ||
| dstF, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, mode(fmode, umask)) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
| defer func() { _ = dstF.Close() }() | ||
|
|
||
| count, err := Copy(ctx, dstF, srcF) | ||
| if err != nil { | ||
| // Close & remove the file in case of partial write | ||
| _ = dstF.Close() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already call close in a deferred function on line 84, so do we need this? In any case, having a second call won't cause any errors as we are throwing away the returned error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same reasoning as above, keeping the way these are handled in sync. |
||
| _ = os.Remove(dst) | ||
| return 0, err | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already call close in a deferred function on line 42, so do we need this? In any case, having a second call won't cause any errors as we are throwing away the returned error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The windows test case would fail here because the file was reported as being in use at the time of removal. Adding in the explicit file closed fixed it and allowed the file to be removed, so it seems like windows has a different requirement/handling that needs the file to be explicitly closed before removing it. I figured it's better to close the file an extra time as opposed to trying to check.