Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 665b6786 authored by Colin Cross's avatar Colin Cross
Browse files

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
parent 05f72de0
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -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 {