Close files properly when returning an error (Arsen6331/itd#29)

This commit is contained in:
Elara 2022-10-17 12:49:49 -07:00
parent bb017b471e
commit a01f1b9d92

View File

@ -70,6 +70,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
if err != nil {
return nil, err
}
defer m.Close()
var manifest ResourceManifest
err = json.NewDecoder(m).Decode(&manifest)
@ -77,6 +78,8 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
return nil, err
}
m.Close()
log.Debug().Msg("Decoded manifest file")
go func() {
@ -124,6 +127,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
Total: srcFi.Size(),
Err: err,
}
src.Close()
return
}
@ -138,6 +142,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
Total: srcFi.Size(),
Err: err,
}
src.Close()
return
}
@ -155,6 +160,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
Total: srcFi.Size(),
Err: err,
}
src.Close()
return
}
@ -189,6 +195,8 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
Sent: n,
Err: err,
}
src.Close()
dst.Close()
return
}