Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c2fc8bc

Browse files
committedJul 10, 2015
pin rm fails appropriately for indirect pins
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent aa1be6b commit c2fc8bc

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed
 

‎pin/pin.go

+18-4
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,26 @@ func (p *pinner) Pin(ctx context.Context, node *mdag.Node, recurse bool) error {
127127
func (p *pinner) Unpin(ctx context.Context, k key.Key, recursive bool) error {
128128
p.lock.Lock()
129129
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":
131139
if recursive {
132140
p.recursePin.RemoveBlock(k)
133141
return nil
134142
} else {
135143
return fmt.Errorf("%s is pinned recursively", k)
136144
}
137-
} else if p.directPin.HasKey(k) {
145+
case "direct":
138146
p.directPin.RemoveBlock(k)
139147
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)
142150
}
143151
}
144152

@@ -152,6 +160,12 @@ func (p *pinner) isInternalPin(key key.Key) bool {
152160
func (p *pinner) IsPinned(k key.Key) (string, bool, error) {
153161
p.lock.RLock()
154162
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) {
155169
if p.recursePin.HasKey(k) {
156170
return "recursive", true, nil
157171
}

0 commit comments

Comments
 (0)
Please sign in to comment.