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:
10
zip/zip.go
10
zip/zip.go
@@ -406,6 +406,8 @@ func Zip(args ZipArgs) error {
|
|||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
var out io.Writer = buf
|
var out io.Writer = buf
|
||||||
|
|
||||||
|
var zipErr error
|
||||||
|
|
||||||
if !args.WriteIfChanged {
|
if !args.WriteIfChanged {
|
||||||
f, err := os.Create(args.OutputFilePath)
|
f, err := os.Create(args.OutputFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -414,7 +416,7 @@ func Zip(args ZipArgs) error {
|
|||||||
|
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if zipErr != nil {
|
||||||
os.Remove(args.OutputFilePath)
|
os.Remove(args.OutputFilePath)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@@ -422,9 +424,9 @@ func Zip(args ZipArgs) error {
|
|||||||
out = f
|
out = f
|
||||||
}
|
}
|
||||||
|
|
||||||
err := zipTo(args, out)
|
zipErr = zipTo(args, out)
|
||||||
if err != nil {
|
if zipErr != nil {
|
||||||
return err
|
return zipErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.WriteIfChanged {
|
if args.WriteIfChanged {
|
||||||
|
Reference in New Issue
Block a user