This repository was archived by the owner on Jun 26, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -98,7 +98,6 @@ func (d *Directory) updateChildEntry(c child) error {
98
98
// new node in the DAG layer.
99
99
func (d * Directory ) localUpdate (c child ) (* dag.ProtoNode , error ) {
100
100
d .lock .Lock ()
101
- defer d .lock .Unlock ()
102
101
103
102
err := d .updateChild (c )
104
103
if err != nil {
@@ -117,13 +116,21 @@ func (d *Directory) localUpdate(c child) (*dag.ProtoNode, error) {
117
116
return nil , dag .ErrNotProtobuf
118
117
}
119
118
120
- err = d .dagService .Add (d .ctx , nd )
119
+ nodeCopy := pbnd .Copy ().(* dag.ProtoNode )
120
+ // We copy the underlying node to add it to the DAG service and
121
+ // propagate the update upwards (outside of the lock) because
122
+ // other callers might operate on this directory node later
123
+ // while *this* update is still in progress.
124
+
125
+ d .lock .Unlock ()
126
+ // NOTE: The original `nd` can't be accessed below this point.
127
+
128
+ err = d .dagService .Add (d .ctx , nodeCopy )
121
129
if err != nil {
122
130
return nil , err
123
131
}
124
132
125
- return pbnd .Copy ().(* dag.ProtoNode ), nil
126
- // TODO: Why do we need a copy?
133
+ return nodeCopy , nil
127
134
}
128
135
129
136
// Update child entry in the underlying UnixFS directory.
You can’t perform that action at this time.
0 commit comments