feat: add content signature xattr cache

This commit is contained in:
Samuel Cui
2026-08-31 21:17:41 +08:00
parent 4eecd3fe31
commit cc5248ea33
19 changed files with 1211 additions and 46 deletions
+27
View File
@@ -1,6 +1,7 @@
package acp
import (
"fmt"
"os"
"path/filepath"
"strings"
@@ -43,6 +44,9 @@ type option struct {
createFlag int
withHash bool
withSignatureCache bool
forceRehash bool
logger *logrus.Logger
eventHanders []EventHandler
}
@@ -64,6 +68,12 @@ func (o *option) check() error {
o.fromDevice.check()
o.toDevice.check()
if o.withSignatureCache {
o.withHash = true
}
if o.forceRehash && !o.withSignatureCache {
return fmt.Errorf("force rehash requires signature cache")
}
if o.logger == nil {
o.logger = logrus.StandardLogger()
}
@@ -132,6 +142,23 @@ func WithHash(b bool) Option {
}
}
// WithSignatureCache enables content-signature reads and writes through xattrs.
// It also enables hashing so cache misses can be refreshed.
func WithSignatureCache(enabled bool) Option {
return func(o *option) *option {
o.withSignatureCache = enabled
return o
}
}
// ForceRehash bypasses signature-cache reads while still refreshing the cache.
func ForceRehash(force bool) Option {
return func(o *option) *option {
o.forceRehash = force
return o
}
}
func WithLogger(logger *logrus.Logger) Option {
return func(o *option) *option {
o.logger = logger