mirror of
https://github.com/packwiz/packwiz.git
synced 2025-10-14 06:54:32 +02:00
Fix unhandled error warnings, error messages (except import.go)
This commit is contained in:
@@ -125,16 +125,21 @@ func (in *Index) updateFile(path string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// Hash usage strategy (may change):
|
||||
// Just use SHA256, overwrite existing hash regardless of what it is
|
||||
// May update later to continue using the same hash that was already being used
|
||||
h, err := GetHashImpl("sha256")
|
||||
if err != nil {
|
||||
_ = f.Close()
|
||||
return err
|
||||
}
|
||||
if _, err := io.Copy(h, f); err != nil {
|
||||
_ = f.Close()
|
||||
return err
|
||||
}
|
||||
err = f.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
hashString := hex.EncodeToString(h.Sum(nil))
|
||||
@@ -270,12 +275,16 @@ func (in Index) Write() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
enc := toml.NewEncoder(f)
|
||||
// Disable indentation
|
||||
enc.Indent = ""
|
||||
return enc.Encode(in)
|
||||
err = enc.Encode(in)
|
||||
if err != nil {
|
||||
_ = f.Close()
|
||||
return err
|
||||
}
|
||||
return f.Close()
|
||||
}
|
||||
|
||||
// RefreshFileWithHash updates a file in the index, given a file hash and whether it is a mod or not
|
||||
|
@@ -88,10 +88,10 @@ func (m Mod) Write() (string, string, error) {
|
||||
return "sha256", "", err
|
||||
}
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
h, err := GetHashImpl("sha256")
|
||||
if err != nil {
|
||||
_ = f.Close()
|
||||
return "", "", err
|
||||
}
|
||||
w := io.MultiWriter(h, f)
|
||||
@@ -101,7 +101,11 @@ func (m Mod) Write() (string, string, error) {
|
||||
enc.Indent = ""
|
||||
err = enc.Encode(m)
|
||||
hashString := hex.EncodeToString(h.Sum(nil))
|
||||
return "sha256", hashString, err
|
||||
if err != nil {
|
||||
_ = f.Close()
|
||||
return "sha256", hashString, err
|
||||
}
|
||||
return "sha256", hashString, f.Close()
|
||||
}
|
||||
|
||||
// GetParsedUpdateData can be used to retrieve updater-specific information after parsing a mod file
|
||||
|
13
core/pack.go
13
core/pack.go
@@ -59,23 +59,24 @@ func (pack *Pack) UpdateIndexHash() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// Hash usage strategy (may change):
|
||||
// Just use SHA256, overwrite existing hash regardless of what it is
|
||||
// May update later to continue using the same hash that was already being used
|
||||
h, err := GetHashImpl("sha256")
|
||||
if err != nil {
|
||||
_ = f.Close()
|
||||
return err
|
||||
}
|
||||
if _, err := io.Copy(h, f); err != nil {
|
||||
_ = f.Close()
|
||||
return err
|
||||
}
|
||||
hashString := hex.EncodeToString(h.Sum(nil))
|
||||
|
||||
pack.Index.HashFormat = "sha256"
|
||||
pack.Index.Hash = hashString
|
||||
return nil
|
||||
return f.Close()
|
||||
}
|
||||
|
||||
// Write saves the pack file
|
||||
@@ -84,12 +85,16 @@ func (pack Pack) Write() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
enc := toml.NewEncoder(f)
|
||||
// Disable indentation
|
||||
enc.Indent = ""
|
||||
return enc.Encode(pack)
|
||||
err = enc.Encode(pack)
|
||||
if err != nil {
|
||||
_ = f.Close()
|
||||
return err
|
||||
}
|
||||
return f.Close()
|
||||
}
|
||||
|
||||
// GetMCVersion gets the version of Minecraft this pack uses, if it has been correctly specified
|
||||
|
Reference in New Issue
Block a user