refactor: replace download-based hash verification with lightweight size check

The previous approach downloaded the entire backup file after upload to
compute a remote SHA-256, which doubles bandwidth cost for every backup.

New approach:
- Local SHA-256 is still computed before upload (stored in record for audit)
- After upload, use provider.List() to check remote file size (single API call)
- If remote size is 0 or mismatches local size → mark failed + auto-delete
- If List() fails, log a warning but don't block (file may have uploaded fine)

This catches 0KB corrupted uploads with zero download overhead.
This commit is contained in:
Awuqing
2026-03-31 12:36:29 +08:00
parent 51f1909a73
commit e5a4aaadb2
2 changed files with 26 additions and 30 deletions

View File

@@ -38,15 +38,6 @@ func SHA256File(path string) (string, error) {
return hex.EncodeToString(hash.Sum(nil)), nil
}
// SHA256Reader 计算 reader 的 SHA-256 哈希值,返回十六进制字符串
func SHA256Reader(reader io.Reader) (string, error) {
hash := sha256.New()
if _, err := io.Copy(hash, reader); err != nil {
return "", fmt.Errorf("compute checksum: %w", err)
}
return hex.EncodeToString(hash.Sum(nil)), nil
}
func sanitizeFileName(value string) string {
builder := strings.Builder{}
for _, char := range strings.TrimSpace(value) {