Перенесите реализацию ЛР 4 на стенд ЛР 5

This commit is contained in:
2026-11-18 15:33:31 +03:00
parent 276dbdad8a
commit 911d97a77a
153 changed files with 17451 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
package attachment
import (
"context"
"crypto/sha256"
"encoding/binary"
"encoding/hex"
"errors"
"github.com/jackc/pgx/v5"
)
// LockHash serializes CAS publication and collection until the transaction ends.
// A collision in the signed first eight digest bytes only adds serialization.
func LockHash(ctx context.Context, tx pgx.Tx, hash []byte) error {
if len(hash) != sha256.Size {
return errors.New("attachment: lock requires a SHA256 hash")
}
_, err := tx.Exec(ctx, `SELECT pg_advisory_xact_lock($1)`, int64(binary.BigEndian.Uint64(hash[:8])))
return err
}
func BlobKey(hash []byte) string { return "blobs/" + hex.EncodeToString(hash) }