diff options
Diffstat (limited to 'lib/db/keyer.go')
-rw-r--r-- | lib/db/keyer.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/db/keyer.go b/lib/db/keyer.go index d60644e447..88103eb07e 100644 --- a/lib/db/keyer.go +++ b/lib/db/keyer.go @@ -62,6 +62,9 @@ const ( // KeyTypeBlockList <block list hash> = BlockList KeyTypeBlockList = 13 + + // KeyTypeBlockListMap <int32 folder ID> <block list hash> <file name> = <nothing> + KeyTypeBlockListMap = 14 ) type keyer interface { @@ -79,6 +82,8 @@ type keyer interface { // block map key stuff (former BlockMap) GenerateBlockMapKey(key, folder, hash, name []byte) (blockMapKey, error) NameFromBlockMapKey(key []byte) []byte + GenerateBlockListMapKey(key, folder, hash, name []byte) (blockListMapKey, error) + NameFromBlockListMapKey(key []byte) []byte // file need index GenerateNeedFileKey(key, folder, name []byte) (needFileKey, error) @@ -203,6 +208,29 @@ func (k blockMapKey) WithoutHashAndName() []byte { return k[:keyPrefixLen+keyFolderLen] } +type blockListMapKey []byte + +func (k defaultKeyer) GenerateBlockListMapKey(key, folder, hash, name []byte) (blockListMapKey, error) { + folderID, err := k.folderIdx.ID(folder) + if err != nil { + return nil, err + } + key = resize(key, keyPrefixLen+keyFolderLen+keyHashLen+len(name)) + key[0] = KeyTypeBlockListMap + binary.BigEndian.PutUint32(key[keyPrefixLen:], folderID) + copy(key[keyPrefixLen+keyFolderLen:], hash) + copy(key[keyPrefixLen+keyFolderLen+keyHashLen:], name) + return key, nil +} + +func (k defaultKeyer) NameFromBlockListMapKey(key []byte) []byte { + return key[keyPrefixLen+keyFolderLen+keyHashLen:] +} + +func (k blockListMapKey) WithoutHashAndName() []byte { + return k[:keyPrefixLen+keyFolderLen] +} + type needFileKey []byte func (k needFileKey) WithoutName() []byte { |