MCPcopy
hub / github.com/perkeep/perkeep / New

Function New

pkg/blobserver/diskpacked/diskpacked.go:124–148  ·  view source on GitHub ↗

New returns a diskpacked storage implementation, adding blobs to the provided directory. It doesn't delete any existing blob pack files.

(dir string)

Source from the content-addressed store, hash-verified

122// the provided directory. It doesn't delete any existing blob pack
123// files.
124func New(dir string) (blobserver.Storage, error) {
125 var maxSize int64
126 if dh, err := os.Open(dir); err == nil {
127 var nBlobFiles, atMax int
128 if fis, err := dh.Readdir(-1); err == nil {
129 // Detect existing max size from size of files, if obvious, and set maxSize to that
130 for _, fi := range fis {
131 if nm := fi.Name(); strings.HasPrefix(nm, "pack-") && strings.HasSuffix(nm, ".blobs") {
132 nBlobFiles++
133 if s := fi.Size(); s > maxSize {
134 maxSize, atMax = fi.Size(), 0
135 } else if s == maxSize {
136 atMax++
137 }
138 }
139 }
140 }
141 // Believe the deduced size only if at least 2 files has that maximum size,
142 // and all files (except one) has the same.
143 if !(atMax > 1 && nBlobFiles == atMax+1) {
144 maxSize = 0
145 }
146 }
147 return newStorage(dir, maxSize, nil)
148}
149
150// newIndex returns a new sorted.KeyValue, using either the given config, or the default.
151func newIndex(root string, indexConf jsonconfig.Obj) (sorted.KeyValue, error) {

Callers 1

NewFunction · 0.92

Calls 6

newStorageFunction · 0.85
HasPrefixMethod · 0.80
OpenMethod · 0.65
ReaddirMethod · 0.65
NameMethod · 0.65
SizeMethod · 0.65

Tested by

no test coverage detected