Skip to content

Commit 9047fed

Browse files
authored
core/commands!: remove deprecated object APIs (#10375)
1 parent 21728eb commit 9047fed

28 files changed

+163
-2033
lines changed

assets/assets.go

+6-18
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import (
99
"github.com/ipfs/kubo/core/coreapi"
1010

1111
"github.com/ipfs/boxo/files"
12-
"github.com/ipfs/boxo/path"
1312
cid "github.com/ipfs/go-cid"
14-
options "github.com/ipfs/kubo/core/coreiface/options"
1513
)
1614

1715
//go:embed init-doc
@@ -39,30 +37,20 @@ func addAssetList(nd *core.IpfsNode, l []string) (cid.Cid, error) {
3937
return cid.Cid{}, err
4038
}
4139

42-
dirb, err := api.Object().New(nd.Context(), options.Object.Type("unixfs-dir"))
43-
if err != nil {
44-
return cid.Cid{}, err
45-
}
46-
47-
basePath := path.FromCid(dirb.Cid())
40+
dirMap := map[string]files.Node{}
4841

4942
for _, p := range l {
5043
d, err := Asset.ReadFile(p)
5144
if err != nil {
5245
return cid.Cid{}, fmt.Errorf("assets: could load Asset '%s': %s", p, err)
5346
}
5447

55-
fp, err := api.Unixfs().Add(nd.Context(), files.NewBytesFile(d))
56-
if err != nil {
57-
return cid.Cid{}, err
58-
}
59-
60-
fname := gopath.Base(p)
48+
dirMap[gopath.Base(p)] = files.NewBytesFile(d)
49+
}
6150

62-
basePath, err = api.Object().AddLink(nd.Context(), basePath, fname, fp)
63-
if err != nil {
64-
return cid.Cid{}, err
65-
}
51+
basePath, err := api.Unixfs().Add(nd.Context(), files.NewMapDirectory(dirMap))
52+
if err != nil {
53+
return cid.Cid{}, err
6654
}
6755

6856
if err := api.Pin().Add(nd.Context(), basePath); err != nil {

bin/ipns-republish

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if [ $? -ne 0 ]; then
1919
fi
2020

2121
# check the object is there
22-
ipfs object stat "$1" >/dev/null
22+
ipfs dag stat "$1" >/dev/null
2323
if [ $? -ne 0 ]; then
2424
echo "error: ipfs cannot find $1"
2525
exit 1

client/rpc/object.go

-172
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
package rpc
22

33
import (
4-
"bytes"
54
"context"
6-
"fmt"
7-
"io"
85

9-
"github.com/ipfs/boxo/ipld/merkledag"
10-
ft "github.com/ipfs/boxo/ipld/unixfs"
116
"github.com/ipfs/boxo/path"
127
"github.com/ipfs/go-cid"
13-
ipld "github.com/ipfs/go-ipld-format"
148
iface "github.com/ipfs/kubo/core/coreiface"
159
caopts "github.com/ipfs/kubo/core/coreiface/options"
1610
)
@@ -21,138 +15,6 @@ type objectOut struct {
2115
Hash string
2216
}
2317

24-
func (api *ObjectAPI) New(ctx context.Context, opts ...caopts.ObjectNewOption) (ipld.Node, error) {
25-
options, err := caopts.ObjectNewOptions(opts...)
26-
if err != nil {
27-
return nil, err
28-
}
29-
30-
var n ipld.Node
31-
switch options.Type {
32-
case "empty":
33-
n = new(merkledag.ProtoNode)
34-
case "unixfs-dir":
35-
n = ft.EmptyDirNode()
36-
default:
37-
return nil, fmt.Errorf("unknown object type: %s", options.Type)
38-
}
39-
40-
return n, nil
41-
}
42-
43-
func (api *ObjectAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.ObjectPutOption) (path.ImmutablePath, error) {
44-
options, err := caopts.ObjectPutOptions(opts...)
45-
if err != nil {
46-
return path.ImmutablePath{}, err
47-
}
48-
49-
var out objectOut
50-
err = api.core().Request("object/put").
51-
Option("inputenc", options.InputEnc).
52-
Option("datafieldenc", options.DataType).
53-
Option("pin", options.Pin).
54-
FileBody(r).
55-
Exec(ctx, &out)
56-
if err != nil {
57-
return path.ImmutablePath{}, err
58-
}
59-
60-
c, err := cid.Parse(out.Hash)
61-
if err != nil {
62-
return path.ImmutablePath{}, err
63-
}
64-
65-
return path.FromCid(c), nil
66-
}
67-
68-
func (api *ObjectAPI) Get(ctx context.Context, p path.Path) (ipld.Node, error) {
69-
r, err := api.core().Block().Get(ctx, p)
70-
if err != nil {
71-
return nil, err
72-
}
73-
b, err := io.ReadAll(r)
74-
if err != nil {
75-
return nil, err
76-
}
77-
78-
return merkledag.DecodeProtobuf(b)
79-
}
80-
81-
func (api *ObjectAPI) Data(ctx context.Context, p path.Path) (io.Reader, error) {
82-
resp, err := api.core().Request("object/data", p.String()).Send(ctx)
83-
if err != nil {
84-
return nil, err
85-
}
86-
if resp.Error != nil {
87-
return nil, resp.Error
88-
}
89-
90-
// TODO: make Data return ReadCloser to avoid copying
91-
defer resp.Close()
92-
b := new(bytes.Buffer)
93-
if _, err := io.Copy(b, resp.Output); err != nil {
94-
return nil, err
95-
}
96-
97-
return b, nil
98-
}
99-
100-
func (api *ObjectAPI) Links(ctx context.Context, p path.Path) ([]*ipld.Link, error) {
101-
var out struct {
102-
Links []struct {
103-
Name string
104-
Hash string
105-
Size uint64
106-
}
107-
}
108-
if err := api.core().Request("object/links", p.String()).Exec(ctx, &out); err != nil {
109-
return nil, err
110-
}
111-
res := make([]*ipld.Link, len(out.Links))
112-
for i, l := range out.Links {
113-
c, err := cid.Parse(l.Hash)
114-
if err != nil {
115-
return nil, err
116-
}
117-
118-
res[i] = &ipld.Link{
119-
Cid: c,
120-
Name: l.Name,
121-
Size: l.Size,
122-
}
123-
}
124-
125-
return res, nil
126-
}
127-
128-
func (api *ObjectAPI) Stat(ctx context.Context, p path.Path) (*iface.ObjectStat, error) {
129-
var out struct {
130-
Hash string
131-
NumLinks int
132-
BlockSize int
133-
LinksSize int
134-
DataSize int
135-
CumulativeSize int
136-
}
137-
if err := api.core().Request("object/stat", p.String()).Exec(ctx, &out); err != nil {
138-
return nil, err
139-
}
140-
141-
c, err := cid.Parse(out.Hash)
142-
if err != nil {
143-
return nil, err
144-
}
145-
146-
return &iface.ObjectStat{
147-
Cid: c,
148-
NumLinks: out.NumLinks,
149-
BlockSize: out.BlockSize,
150-
LinksSize: out.LinksSize,
151-
DataSize: out.DataSize,
152-
CumulativeSize: out.CumulativeSize,
153-
}, nil
154-
}
155-
15618
func (api *ObjectAPI) AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...caopts.ObjectAddLinkOption) (path.ImmutablePath, error) {
15719
options, err := caopts.ObjectAddLinkOptions(opts...)
15820
if err != nil {
@@ -191,40 +53,6 @@ func (api *ObjectAPI) RmLink(ctx context.Context, base path.Path, link string) (
19153
return path.FromCid(c), nil
19254
}
19355

194-
func (api *ObjectAPI) AppendData(ctx context.Context, p path.Path, r io.Reader) (path.ImmutablePath, error) {
195-
var out objectOut
196-
err := api.core().Request("object/patch/append-data", p.String()).
197-
FileBody(r).
198-
Exec(ctx, &out)
199-
if err != nil {
200-
return path.ImmutablePath{}, err
201-
}
202-
203-
c, err := cid.Parse(out.Hash)
204-
if err != nil {
205-
return path.ImmutablePath{}, err
206-
}
207-
208-
return path.FromCid(c), nil
209-
}
210-
211-
func (api *ObjectAPI) SetData(ctx context.Context, p path.Path, r io.Reader) (path.ImmutablePath, error) {
212-
var out objectOut
213-
err := api.core().Request("object/patch/set-data", p.String()).
214-
FileBody(r).
215-
Exec(ctx, &out)
216-
if err != nil {
217-
return path.ImmutablePath{}, err
218-
}
219-
220-
c, err := cid.Parse(out.Hash)
221-
if err != nil {
222-
return path.ImmutablePath{}, err
223-
}
224-
225-
return path.FromCid(c), nil
226-
}
227-
22856
type change struct {
22957
Type iface.ChangeType
23058
Path string

core/commands/commands_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ func TestCommands(t *testing.T) {
6161
"/dag/stat",
6262
"/dht",
6363
"/dht/query",
64+
"/dht/findprovs",
65+
"/dht/findpeer",
66+
"/dht/get",
67+
"/dht/provide",
68+
"/dht/put",
6469
"/routing",
6570
"/routing/put",
6671
"/routing/get",

core/commands/dht.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@ import (
1515
var ErrNotDHT = errors.New("routing service is not a DHT")
1616

1717
var DhtCmd = &cmds.Command{
18+
Status: cmds.Deprecated,
1819
Helptext: cmds.HelpText{
1920
Tagline: "Issue commands directly through the DHT.",
2021
ShortDescription: ``,
2122
},
2223

2324
Subcommands: map[string]*cmds.Command{
24-
"query": queryDhtCmd,
25+
"query": queryDhtCmd,
26+
"findprovs": RemovedDHTCmd,
27+
"findpeer": RemovedDHTCmd,
28+
"get": RemovedDHTCmd,
29+
"put": RemovedDHTCmd,
30+
"provide": RemovedDHTCmd,
2531
},
2632
}
2733

@@ -32,6 +38,7 @@ type kademlia interface {
3238
}
3339

3440
var queryDhtCmd = &cmds.Command{
41+
Status: cmds.Deprecated,
3542
Helptext: cmds.HelpText{
3643
Tagline: "Find the closest Peer IDs to a given Peer ID by querying the DHT.",
3744
ShortDescription: "Outputs a list of newline-delimited Peer IDs.",
@@ -114,3 +121,12 @@ var queryDhtCmd = &cmds.Command{
114121
},
115122
Type: routing.QueryEvent{},
116123
}
124+
var RemovedDHTCmd = &cmds.Command{
125+
Status: cmds.Removed,
126+
Helptext: cmds.HelpText{
127+
Tagline: "Removed, use 'ipfs routing' instead.",
128+
},
129+
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
130+
return errors.New("removed, use 'ipfs routing' instead")
131+
},
132+
}

0 commit comments

Comments
 (0)