MCPcopy
hub / github.com/ha/doozerd / apply

Method apply

src/pkg/store/node.go:121–169  ·  view source on GitHub ↗
(seqn int64, mut string)

Source from the content-addressed store, hash-verified

119}
120
121func (n node) apply(seqn int64, mut string) (rep node, ev Event) {
122 ev.Seqn, ev.Rev, ev.Mut = seqn, seqn, mut
123 if mut == Nop {
124 ev.Path = "/"
125 ev.Rev = nop
126 rep = n
127 ev.Getter = rep
128 return
129 }
130
131 var rev int64
132 var keep bool
133 ev.Path, ev.Body, rev, keep, ev.Err = decode(mut)
134
135 if ev.Err == nil && keep {
136 components := split(ev.Path)
137 for i := 0; i < len(components)-1; i++ {
138 _, dirRev := n.get(components[0 : i+1])
139 if dirRev == Missing {
140 break
141 }
142 if dirRev != Dir {
143 ev.Err = os.ENOTDIR
144 break
145 }
146 }
147 }
148
149 if ev.Err == nil {
150 _, curRev := n.Get(ev.Path)
151 if rev != Clobber && rev < curRev {
152 ev.Err = ErrRevMismatch
153 } else if curRev == Dir {
154 ev.Err = os.EISDIR
155 }
156 }
157
158 if ev.Err != nil {
159 ev.Path, ev.Body, rev, keep = ErrorPath, ev.Err.String(), Clobber, true
160 }
161
162 if !keep {
163 ev.Rev = Missing
164 }
165
166 rep = n.setp(ev.Path, ev.Body, ev.Rev, keep)
167 ev.Getter = rep
168 return
169}

Callers 11

TestNodeApplyDelFunction · 0.95
processMethod · 0.80
TestSnapFunction · 0.80
TestNodeApplySetFunction · 0.80
TestNodeApplyNopFunction · 0.80
TestNodeApplyBadMutationFunction · 0.80
TestNodeApplyRevMismatchFunction · 0.80
TestNodeNotADirectoryFunction · 0.80
TestNodeIsADirectoryFunction · 0.80

Calls 6

getMethod · 0.95
GetMethod · 0.95
setpMethod · 0.95
decodeFunction · 0.85
splitFunction · 0.85
StringMethod · 0.45

Tested by 10

TestNodeApplyDelFunction · 0.76
TestSnapFunction · 0.64
TestNodeApplySetFunction · 0.64
TestNodeApplyNopFunction · 0.64
TestNodeApplyBadMutationFunction · 0.64
TestNodeApplyRevMismatchFunction · 0.64
TestNodeNotADirectoryFunction · 0.64
TestNodeIsADirectoryFunction · 0.64