archive.writeCompressed: bubble up error when closing archive file (MR 25)
This also prevents a double Close() if the compressor is ever set to 'fd'
This commit is contained in:
@@ -279,13 +279,21 @@ func (archive *Archive) addFile(source string, dest string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (archive *Archive) writeCompressed(path string, mode os.FileMode) error {
|
func (archive *Archive) writeCompressed(path string, mode os.FileMode) (err error) {
|
||||||
|
|
||||||
|
var compressor io.WriteCloser
|
||||||
|
defer func() {
|
||||||
|
e := compressor.Close()
|
||||||
|
if e != nil && err == nil {
|
||||||
|
err = e
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
fd, err := os.Create(path)
|
fd, err := os.Create(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// Note: fd.Close omitted since it'll be closed in "compressor"
|
||||||
var compressor io.WriteCloser
|
|
||||||
|
|
||||||
switch archive.compress_format {
|
switch archive.compress_format {
|
||||||
case FormatGzip:
|
case FormatGzip:
|
||||||
@@ -326,10 +334,6 @@ func (archive *Archive) writeCompressed(path string, mode os.FileMode) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := compressor.Close(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// call fsync just to be sure
|
// call fsync just to be sure
|
||||||
if err := fd.Sync(); err != nil {
|
if err := fd.Sync(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
Reference in New Issue
Block a user