New returns a diskpacked storage implementation, adding blobs to the provided directory. It doesn't delete any existing blob pack files.
(dir string)
| 122 | // the provided directory. It doesn't delete any existing blob pack |
| 123 | // files. |
| 124 | func 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. |
| 151 | func newIndex(root string, indexConf jsonconfig.Obj) (sorted.KeyValue, error) { |