@@ -24,6 +24,9 @@ var log = eventlog.Logger("coreunix")
24
24
// Add builds a merkledag from the a reader, pinning all objects to the local
25
25
// datastore. Returns a key representing the root node.
26
26
func Add (n * core.IpfsNode , r io.Reader ) (string , error ) {
27
+ unlock := n .Blockstore .RLock ()
28
+ defer unlock ()
29
+
27
30
// TODO more attractive function signature importer.BuildDagFromReader
28
31
dagNode , err := importer .BuildDagFromReader (
29
32
r ,
@@ -44,6 +47,9 @@ func Add(n *core.IpfsNode, r io.Reader) (string, error) {
44
47
45
48
// AddR recursively adds files in |path|.
46
49
func AddR (n * core.IpfsNode , root string ) (key string , err error ) {
50
+ unlock := n .Blockstore .RLock ()
51
+ defer unlock ()
52
+
47
53
f , err := os .Open (root )
48
54
if err != nil {
49
55
return "" , err
@@ -79,6 +85,9 @@ func AddR(n *core.IpfsNode, root string) (key string, err error) {
79
85
// Returns the path of the added file ("<dir hash>/filename"), the DAG node of
80
86
// the directory, and and error if any.
81
87
func AddWrapped (n * core.IpfsNode , r io.Reader , filename string ) (string , * merkledag.Node , error ) {
88
+ unlock := n .Blockstore .RLock ()
89
+ defer unlock ()
90
+
82
91
file := files .NewReaderFile (filename , ioutil .NopCloser (r ), nil )
83
92
dir := files .NewSliceFile ("" , []files.File {file })
84
93
dagnode , err := addDir (n , dir )
0 commit comments