mirror of
https://github.com/kopia/kopia.git
synced 2026-05-10 15:54:20 -04:00
* fixed new gocritic violations * fixed new 'contextcheck' violations * fixed 'gosec' warnings * suppressed ireturn and varnamelen linters * fixed tenv violations, enabled building robustness tests on arm64 * fixed remaining linux failures * makefile: fixed 'lint-all' target when running on arm64 * linter: increase deadline * disable nilnil linter - to be enabled in separate PR
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
//go:build darwin || (linux && amd64)
|
|
// +build darwin linux,amd64
|
|
|
|
package snapmeta
|
|
|
|
// Index is a map of index name to the keys associated
|
|
// with that index name.
|
|
type Index map[string]map[string]struct{}
|
|
|
|
// AddToIndex adds a key to the index of the given name.
|
|
func (idx Index) AddToIndex(key, indexName string) {
|
|
if _, ok := idx[indexName]; !ok {
|
|
idx[indexName] = make(map[string]struct{})
|
|
}
|
|
|
|
idx[indexName][key] = struct{}{}
|
|
}
|
|
|
|
// RemoveFromIndex removes a key from the index of the given name.
|
|
func (idx Index) RemoveFromIndex(key, indexName string) {
|
|
if _, ok := idx[indexName]; !ok {
|
|
return
|
|
}
|
|
|
|
delete(idx[indexName], key)
|
|
}
|
|
|
|
// GetKeys returns the list of keys associated with the given index name.
|
|
func (idx Index) GetKeys(indexName string) (ret []string) {
|
|
if _, ok := idx[indexName]; !ok {
|
|
return ret
|
|
}
|
|
|
|
for k := range idx[indexName] {
|
|
ret = append(ret, k)
|
|
}
|
|
|
|
return ret
|
|
}
|
|
|
|
// IsKeyInIndex will return true if the given index name contains the
|
|
// provided key.
|
|
func (idx Index) IsKeyInIndex(key, indexName string) bool {
|
|
if _, ok := idx[indexName]; ok {
|
|
_, keyExists := idx[indexName][key]
|
|
return keyExists
|
|
}
|
|
|
|
return false
|
|
}
|