@@ -127,18 +127,26 @@ func (p *pinner) Pin(ctx context.Context, node *mdag.Node, recurse bool) error {
127
127
func (p * pinner ) Unpin (ctx context.Context , k key.Key , recursive bool ) error {
128
128
p .lock .Lock ()
129
129
defer p .lock .Unlock ()
130
- if p .recursePin .HasKey (k ) {
130
+ reason , pinned , err := p .isPinned (k )
131
+ if err != nil {
132
+ return err
133
+ }
134
+ if ! pinned {
135
+ return fmt .Errorf ("%s is not pinned" , k )
136
+ }
137
+ switch reason {
138
+ case "recursive" :
131
139
if recursive {
132
140
p .recursePin .RemoveBlock (k )
133
141
return nil
134
142
} else {
135
143
return fmt .Errorf ("%s is pinned recursively" , k )
136
144
}
137
- } else if p . directPin . HasKey ( k ) {
145
+ case "direct" :
138
146
p .directPin .RemoveBlock (k )
139
147
return nil
140
- } else {
141
- return fmt .Errorf ("%s is not pinned" , k )
148
+ default :
149
+ return fmt .Errorf ("%s is pinned indirectly under %s " , k , reason )
142
150
}
143
151
}
144
152
@@ -152,6 +160,12 @@ func (p *pinner) isInternalPin(key key.Key) bool {
152
160
func (p * pinner ) IsPinned (k key.Key ) (string , bool , error ) {
153
161
p .lock .RLock ()
154
162
defer p .lock .RUnlock ()
163
+ return p .isPinned (k )
164
+ }
165
+
166
+ // isPinned is the implementation of IsPinned that does not lock.
167
+ // intended for use by other pinned methods that already take locks
168
+ func (p * pinner ) isPinned (k key.Key ) (string , bool , error ) {
155
169
if p .recursePin .HasKey (k ) {
156
170
return "recursive" , true , nil
157
171
}
0 commit comments