把 github.com/Autumn-27/norma v0.4.3(commit 320ae32)的源码复制到 third_party/norma,并用 go.mod 的 replace 指向本地副本。上游删除仓库或 改写 tag 都不再影响本仓库构建。 - 已验证 GOPROXY=off 下可完整编译并打出发行包 - go.sum 中该模块的两条校验记录随之删除(本地 replace 不需要哈希) - 升级方法与授权注意事项见 third_party/README.md
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package noa
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
)
|
|
|
|
// memArchiver is an in-memory Archiver for tests: it records what was written
|
|
// so assertions can inspect the archive without touching a filesystem.
|
|
type memArchiver struct {
|
|
mu sync.Mutex
|
|
files map[string][]byte
|
|
order []string
|
|
failOn string // block id whose Write should fail
|
|
removed []string
|
|
}
|
|
|
|
func newMemArchiver() *memArchiver { return &memArchiver{files: map[string][]byte{}} }
|
|
|
|
func (a *memArchiver) Write(tier Tier, blockID, startRef, endRef string, content []byte) (string, string, error) {
|
|
a.mu.Lock()
|
|
defer a.mu.Unlock()
|
|
if a.failOn == blockID {
|
|
return "", "", fmt.Errorf("simulated write failure for %s", blockID)
|
|
}
|
|
rel := ArchiveTierDir(tier) + "/" + ArchiveFileName(blockID, startRef, endRef)
|
|
abs := "/archive/" + rel
|
|
a.files[abs] = append([]byte(nil), content...)
|
|
a.order = append(a.order, abs)
|
|
return abs, rel, nil
|
|
}
|
|
|
|
func (a *memArchiver) Remove(abs string) error {
|
|
a.mu.Lock()
|
|
defer a.mu.Unlock()
|
|
delete(a.files, abs)
|
|
a.removed = append(a.removed, abs)
|
|
return nil
|
|
}
|
|
|
|
func (a *memArchiver) content(abs string) string {
|
|
a.mu.Lock()
|
|
defer a.mu.Unlock()
|
|
return string(a.files[abs])
|
|
}
|
|
|
|
func (a *memArchiver) count() int {
|
|
a.mu.Lock()
|
|
defer a.mu.Unlock()
|
|
return len(a.files)
|
|
}
|