Fix removing partial zip file on error

Fix the shadowed err variable so that it is visible to the defer
function that removes the partial zip file on error.

Bug: 182761771
Test: manual
Change-Id: Ia67ac4bca5ef0107466edf25a76c74d70c243d3f
This commit is contained in:
Colin Cross
2021-03-15 15:28:40 -07:00
parent 05f72de083
commit 665b6786b8

View File

@@ -406,6 +406,8 @@ func Zip(args ZipArgs) error {
buf := &bytes.Buffer{}
var out io.Writer = buf
var zipErr error
if !args.WriteIfChanged {
f, err := os.Create(args.OutputFilePath)
if err != nil {
@@ -414,7 +416,7 @@ func Zip(args ZipArgs) error {
defer f.Close()
defer func() {
if err != nil {
if zipErr != nil {
os.Remove(args.OutputFilePath)
}
}()
@@ -422,9 +424,9 @@ func Zip(args ZipArgs) error {
out = f
}
err := zipTo(args, out)
if err != nil {
return err
zipErr = zipTo(args, out)
if zipErr != nil {
return zipErr
}
if args.WriteIfChanged {