fix: issue with downloading without hooks

This commit is contained in:
David Allen 2025-08-28 19:43:53 -06:00
parent 2536848541
commit f897bc3ca5
Signed by: towk
GPG key ID: 0430CDBE22619155

View file

@ -72,10 +72,14 @@ func addToArchive(tw *tar.Writer, filename string, hooks []makeshift.Hook) error
}
}
// open file to write to archive
// use original file if no hooks to write archive
if len(hooks) == 0 {
file, err = os.Open(filename)
} else {
file, err = os.Open(tempfile)
}
if err != nil {
return fmt.Errorf("failed to open temporary file: %v", err)
return fmt.Errorf("failed to open archive file: %v", err)
}
defer file.Close()
@ -108,16 +112,22 @@ func addToArchive(tw *tar.Writer, filename string, hooks []makeshift.Hook) error
}
// copy file content to tar archive
if len(hooks) == 0 {
_, err = io.Copy(tw, file)
} else {
_, err = io.Copy(tw, strings.NewReader(string(data.([]byte))))
}
if err != nil {
return err
}
// delete the temporary file since we're done with it
if len(hooks) != 0 {
err = os.Remove(tempfile)
if err != nil {
return err
}
}
return nil
}