func Unpin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]*cid.Cid, error) { var unpinned []*cid.Cid for _, p := range paths { p, err := path.ParsePath(p) if err != nil { return nil, err } k, err := core.ResolveToCid(ctx, n, p) if err != nil { return nil, err } ctx, cancel := context.WithCancel(ctx) defer cancel() err = n.Pinning.Unpin(ctx, k, recursive) if err != nil { return nil, err } unpinned = append(unpinned, k) } err := n.Pinning.Flush() if err != nil { return nil, err } return unpinned, nil }
func pinLsKeys(args []string, typeStr string, ctx context.Context, n *core.IpfsNode) (map[string]RefKeyObject, error) { mode, ok := pin.StringToPinMode(typeStr) if !ok { return nil, fmt.Errorf("invalid pin mode '%s'", typeStr) } keys := make(map[string]RefKeyObject) for _, p := range args { pth, err := path.ParsePath(p) if err != nil { return nil, err } c, err := core.ResolveToCid(ctx, n, pth) if err != nil { return nil, err } pinType, pinned, err := n.Pinning.IsPinnedWithType(c, mode) if err != nil { return nil, err } if !pinned { return nil, fmt.Errorf("path '%s' is not pinned", p) } switch pinType { case "direct", "indirect", "recursive", "internal": default: pinType = "indirect through " + pinType } keys[c.String()] = RefKeyObject{ Type: pinType, } } return keys, nil }