Skip to content

Commit

Permalink
change is_pinned out type
Browse files Browse the repository at this point in the history
  • Loading branch information
petar committed Jul 27, 2020
1 parent 2e62575 commit cd75557
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions core/commands/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ type AddPinOutput struct {
}

type IsPinnedOutput struct {
CIDs []string
Pinned []bool
Keys map[string]bool // CID -> is pinned
}

const (
Expand Down Expand Up @@ -305,10 +304,7 @@ Checks whether an object is already pinned.
return err
}

out := &IsPinnedOutput{
CIDs: make([]string, 0, len(req.Arguments)),
Pinned: make([]bool, 0, len(req.Arguments)),
}
out := &IsPinnedOutput{}
for _, b := range req.Arguments {
rp, err := api.ResolvePath(req.Context, path.New(b))
if err != nil {
Expand All @@ -319,20 +315,19 @@ Checks whether an object is already pinned.
if _, pinned, err := api.Pin().IsPinned(req.Context, rp, o); err != nil {
return err
} else {
out.CIDs = append(out.CIDs, id)
out.Pinned = append(out.Pinned, pinned)
out.Keys[id] = pinned
}
}

return cmds.EmitOnce(res, out)
},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *IsPinnedOutput) error {
for i := range out.CIDs {
if out.Pinned[i] {
fmt.Fprintf(w, "pinned %s\n", out.CIDs[i])
for k, pinned := range out.Keys {
if pinned {
fmt.Fprintf(w, "pinned %s\n", k)
} else {
fmt.Fprintf(w, "not pinned %s\n", out.CIDs[i])
fmt.Fprintf(w, "not pinned %s\n", k)
}
}

Expand Down

0 comments on commit cd75557

Please sign in to comment.