forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dir_block_map_memory.go
55 lines (44 loc) · 1.33 KB
/
dir_block_map_memory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2019 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
package libkbfs
import (
"context"
"github.com/keybase/client/go/kbfs/data"
"github.com/pkg/errors"
)
// dirBlockMapMemory is an internal structure to track file block
// data in memory when putting blocks.
type dirBlockMapMemory struct {
blocks map[data.BlockPointer]*data.DirBlock
}
var _ dirBlockMap = (*dirBlockMapMemory)(nil)
func newDirBlockMapMemory() *dirBlockMapMemory {
return &dirBlockMapMemory{make(map[data.BlockPointer]*data.DirBlock)}
}
func (dbmm *dirBlockMapMemory) putBlock(
_ context.Context, ptr data.BlockPointer, block *data.DirBlock) error {
dbmm.blocks[ptr] = block
return nil
}
func (dbmm *dirBlockMapMemory) getBlock(
_ context.Context, ptr data.BlockPointer) (*data.DirBlock, error) {
block, ok := dbmm.blocks[ptr]
if !ok {
return nil, errors.Errorf("No such block for %s", ptr)
}
return block, nil
}
func (dbmm *dirBlockMapMemory) hasBlock(
_ context.Context, ptr data.BlockPointer) (bool, error) {
_, ok := dbmm.blocks[ptr]
return ok, nil
}
func (dbmm *dirBlockMapMemory) deleteBlock(
_ context.Context, ptr data.BlockPointer) error {
delete(dbmm.blocks, ptr)
return nil
}
func (dbmm *dirBlockMapMemory) numBlocks() int {
return len(dbmm.blocks)
}