Skip to content

Commit c552d08

Browse files
committed
core/commands!: remove deprecated object APIs
1 parent 21728eb commit c552d08

27 files changed

+49
-2437
lines changed

assets/assets.go

Lines changed: 6 additions & 18 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 215 deletions
Original file line numberDiff line numberDiff line change
@@ -1,230 +1,15 @@
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"
15-
caopts "github.com/ipfs/kubo/core/coreiface/options"
169
)
1710

1811
type ObjectAPI HttpApi
1912

20-
type objectOut struct {
21-
Hash string
22-
}
23-
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-
156-
func (api *ObjectAPI) AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...caopts.ObjectAddLinkOption) (path.ImmutablePath, error) {
157-
options, err := caopts.ObjectAddLinkOptions(opts...)
158-
if err != nil {
159-
return path.ImmutablePath{}, err
160-
}
161-
162-
var out objectOut
163-
err = api.core().Request("object/patch/add-link", base.String(), name, child.String()).
164-
Option("create", options.Create).
165-
Exec(ctx, &out)
166-
if err != nil {
167-
return path.ImmutablePath{}, err
168-
}
169-
170-
c, err := cid.Parse(out.Hash)
171-
if err != nil {
172-
return path.ImmutablePath{}, err
173-
}
174-
175-
return path.FromCid(c), nil
176-
}
177-
178-
func (api *ObjectAPI) RmLink(ctx context.Context, base path.Path, link string) (path.ImmutablePath, error) {
179-
var out objectOut
180-
err := api.core().Request("object/patch/rm-link", base.String(), link).
181-
Exec(ctx, &out)
182-
if err != nil {
183-
return path.ImmutablePath{}, err
184-
}
185-
186-
c, err := cid.Parse(out.Hash)
187-
if err != nil {
188-
return path.ImmutablePath{}, err
189-
}
190-
191-
return path.FromCid(c), nil
192-
}
193-
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-
22813
type change struct {
22914
Type iface.ChangeType
23015
Path string

core/commands/add.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,6 @@ want to use a 1024 times larger chunk sizes for most files.
115115
> ipfs add --chunker=rabin-512-1024-2048 ipfs-logo.svg
116116
added Qmf1hDN65tR55Ubh2RN1FPxr69xq3giVBz1KApsresY8Gn ipfs-logo.svg
117117
118-
You can now check what blocks have been created by:
119-
120-
> ipfs object links QmafrLBfzRLV4XSH1XcaMMeaXEUhDJjmtDfsYU95TrWG87
121-
QmY6yj1GsermExDXoosVE3aSPxdMNYr6aKuw3nA8LoWPRS 2059
122-
Qmf7ZQeSxq2fJVJbCmgTrLLVN9tDR9Wy5k75DxQKuz5Gyt 1195
123-
> ipfs object links Qmf1hDN65tR55Ubh2RN1FPxr69xq3giVBz1KApsresY8Gn
124-
QmY6yj1GsermExDXoosVE3aSPxdMNYr6aKuw3nA8LoWPRS 2059
125-
QmerURi9k4XzKCaaPbsK6BL5pMEjF7PGphjDvkkjDtsVf3 868
126-
QmQB28iwSriSUSMqG2nXDTLtdPHgWb4rebBrU7Q1j4vxPv 338
127-
128118
Finally, a note on hash (CID) determinism and 'ipfs add' command.
129119
130120
Almost all the flags provided by this command will change the final CID, and

core/commands/commands_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,7 @@ func TestCommands(t *testing.T) {
120120
"/name/pubsub/subs",
121121
"/name/resolve",
122122
"/object",
123-
"/object/data",
124123
"/object/diff",
125-
"/object/get",
126-
"/object/links",
127-
"/object/new",
128-
"/object/patch",
129-
"/object/patch/add-link",
130-
"/object/patch/append-data",
131-
"/object/patch/rm-link",
132-
"/object/patch/set-data",
133-
"/object/put",
134-
"/object/stat",
135124
"/p2p",
136125
"/p2p/close",
137126
"/p2p/forward",

0 commit comments

Comments
 (0)