feat: add checksum for git downloader

This commit is contained in:
2025-06-20 19:35:22 +03:00
parent b5474b1eb4
commit 6bccce1db4
15 changed files with 343 additions and 65 deletions

55
pkg/dl/utils.go Normal file
View File

@ -0,0 +1,55 @@
// ALR - Any Linux Repository
// Copyright (C) 2025 The ALR Authors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package dl
import (
"hash"
"io"
"os"
"path/filepath"
)
func HashDir(dirPath string, h hash.Hash) error {
err := filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// Skip .git directory
if info.IsDir() && info.Name() == ".git" {
return filepath.SkipDir
}
// Skip directories (only process files)
if !info.Mode().IsRegular() {
return nil
}
// Open file
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
// Write file content to hasher
if _, err := io.Copy(h, f); err != nil {
return err
}
return nil
})
if err != nil {
return err
}
return nil
}