internal/download: remove containsHash

This commit is contained in:
Felix Lange 2025-05-14 11:19:03 +02:00
parent e127b9f71e
commit 47193f6459

View file

@ -30,7 +30,6 @@ import (
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
"slices"
"strings" "strings"
) )
@ -128,16 +127,6 @@ func (db *ChecksumDB) Files() iter.Seq[string] {
} }
} }
// findHash returns the known hash of a file.
func (db *ChecksumDB) findHash(basename string) string {
for _, e := range db.hashes {
if e.file == basename {
return e.hash
}
}
return ""
}
// Verify checks whether the given file is valid according to the checksum database. // Verify checks whether the given file is valid according to the checksum database.
func (db *ChecksumDB) Verify(path string) error { func (db *ChecksumDB) Verify(path string) error {
basename := filepath.Base(path) basename := filepath.Base(path)
@ -244,6 +233,16 @@ func (db *ChecksumDB) DownloadFile(url, dstPath string) error {
return os.Rename(tmpfile, dstPath) return os.Rename(tmpfile, dstPath)
} }
// findHash returns the known hash of a file.
func (db *ChecksumDB) findHash(basename string) string {
for _, e := range db.hashes {
if e.file == basename {
return e.hash
}
}
return ""
}
// FindVersion returns the current known version of a tool, if it is defined in the file. // FindVersion returns the current known version of a tool, if it is defined in the file.
func (db *ChecksumDB) FindVersion(tool string) (string, error) { func (db *ChecksumDB) FindVersion(tool string) (string, error) {
for _, e := range db.versions { for _, e := range db.versions {
@ -267,12 +266,6 @@ func (db *ChecksumDB) FindURL(basename string) (string, error) {
return "", fmt.Errorf("file %q does not exist in checksum database", basename) return "", fmt.Errorf("file %q does not exist in checksum database", basename)
} }
func (db *ChecksumDB) containsHash(basename, hash string) bool {
return slices.ContainsFunc(db.hashes, func(e hashEntry) bool {
return e.file == basename && e.hash == hash
})
}
type downloadWriter struct { type downloadWriter struct {
file *os.File file *os.File
dstBuf *bufio.Writer dstBuf *bufio.Writer