Files
stalwart-migrator/internal/backup/hash.go
T
jcoffey-dev 719a945d64 Initial commit: stalwart-migrator design and scaffolding
In-place upgrade tool for Stalwart Mail Server (0.15.5 -> latest) with
checkpointed rollback and post-migration validation. Design stage; see
ARCHITECTURE.md.
2026-08-22 18:17:17 -07:00

26 lines
537 B
Go

package backup
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"os"
)
// hashFile returns a file's SHA256 and size, for recording as a
// checkpoint.Artifact.
func hashFile(path string) (sha256Hex string, size int64, err error) {
f, err := os.Open(path)
if err != nil {
return "", 0, fmt.Errorf("backup: hash %s: %w", path, err)
}
defer f.Close()
h := sha256.New()
n, err := io.Copy(h, f)
if err != nil {
return "", 0, fmt.Errorf("backup: hash %s: %w", path, err)
}
return hex.EncodeToString(h.Sum(nil)), n, nil
}