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 3093b6c

Browse files
committedNov 22, 2018
Add support for global --cid-base option for 'files ls' and 'stat'.
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
1 parent fa760af commit 3093b6c

File tree

8 files changed

+33
-13
lines changed

8 files changed

+33
-13
lines changed
 

‎core/commands/files.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ import (
1515
iface "github.com/ipfs/go-ipfs/core/coreapi/interface"
1616

1717
humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
18+
mfs "gx/ipfs/QmQr1qYm6Ww3ePruqLs2QhSZAHHsW2CzePNTEp48AT3Mg1/go-mfs"
1819
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
1920
ft "gx/ipfs/QmUnHNqhSB1JgzVCxL1Kz3yb4bdyB4q1Z9AD5AUBVmt3fZ/go-unixfs"
20-
mfs "gx/ipfs/QmV8mXUh1M9qztax7vVdL1Apuz4c1eJZC5YactGxaJfWom/go-mfs"
2121
bservice "gx/ipfs/QmVDTbzzTwnuBwNbJdhW3u7LoBQp46bezm9yp4z1RoEepM/go-blockservice"
22+
apicid "gx/ipfs/QmVjZoEZg2oxXGFGjbD28x3gGN6ALHAW6BN2LKRUcaJ21i/go-cidutil/apicid"
2223
offline "gx/ipfs/QmYZwey1thDTynSrvd6qQkX24UpTka6TFhQ2v569UpoqxD/go-ipfs-exchange-offline"
2324
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
2425
dag "gx/ipfs/QmcGt25mrjuB2kKW2zhPbXVZNHc4yoTDQ65NA8m6auP2f1/go-merkledag"
@@ -76,7 +77,7 @@ var hashOption = cmdkit.StringOption(filesHashOptionName, "Hash function to use.
7677
var errFormat = errors.New("format was set by multiple options. Only one format option is allowed")
7778

7879
type statOutput struct {
79-
Hash string
80+
Hash apicid.Hash
8081
Size uint64
8182
CumulativeSize uint64
8283
Blocks int
@@ -172,7 +173,7 @@ var filesStatCmd = &cmds.Command{
172173
Encoders: cmds.EncoderMap{
173174
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *statOutput) error {
174175
s, _ := statGetFormatOptions(req)
175-
s = strings.Replace(s, "<hash>", out.Hash, -1)
176+
s = strings.Replace(s, "<hash>", out.Hash.String(), -1)
176177
s = strings.Replace(s, "<size>", fmt.Sprintf("%d", out.Size), -1)
177178
s = strings.Replace(s, "<cumulsize>", fmt.Sprintf("%d", out.CumulativeSize), -1)
178179
s = strings.Replace(s, "<childs>", fmt.Sprintf("%d", out.Blocks), -1)
@@ -243,15 +244,15 @@ func statNode(nd ipld.Node) (*statOutput, error) {
243244
}
244245

245246
return &statOutput{
246-
Hash: c.String(),
247+
Hash: apicid.FromCid(c),
247248
Blocks: len(nd.Links()),
248249
Size: d.FileSize(),
249250
CumulativeSize: cumulsize,
250251
Type: ndtype,
251252
}, nil
252253
case *dag.RawNode:
253254
return &statOutput{
254-
Hash: c.String(),
255+
Hash: apicid.FromCid(c),
255256
Blocks: 0,
256257
Size: cumulsize,
257258
CumulativeSize: cumulsize,
@@ -470,7 +471,7 @@ Examples:
470471
if err != nil {
471472
return err
472473
}
473-
out.Entries[0].Hash = nd.Cid().String()
474+
out.Entries[0].Hash = apicid.FromCid(nd.Cid())
474475
}
475476
return cmds.EmitOnce(res, out)
476477
default:

‎core/core.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
pstore "gx/ipfs/QmQAGG1zxfePqj2t7bLxyN8AFccZ889DDR9Gn8kVLDrGZo/go-libp2p-peerstore"
3737
mafilter "gx/ipfs/QmQJRvWaYAvU3Mdtk33ADXr9JAZwKMBYBGPkRQBDvyj2nn/go-maddr-filter"
3838
ifconnmgr "gx/ipfs/QmQSucBpqUVQ5Q1stDmm2Bon4Tq4KNhNXuVmLMraARoUoh/go-libp2p-interface-connmgr"
39+
mfs "gx/ipfs/QmQr1qYm6Ww3ePruqLs2QhSZAHHsW2CzePNTEp48AT3Mg1/go-mfs"
3940
dht "gx/ipfs/QmQsw6Nq2A345PqChdtbWVoYbSno7uqRDHwYmYpbPHmZNc/go-libp2p-kad-dht"
4041
dhtopts "gx/ipfs/QmQsw6Nq2A345PqChdtbWVoYbSno7uqRDHwYmYpbPHmZNc/go-libp2p-kad-dht/opts"
4142
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
@@ -50,7 +51,6 @@ import (
5051
ft "gx/ipfs/QmUnHNqhSB1JgzVCxL1Kz3yb4bdyB4q1Z9AD5AUBVmt3fZ/go-unixfs"
5152
psrouter "gx/ipfs/QmV1Z5sZeGL1yy4aKheYgByb4vpaiHrDiwewcH3Sq4YVrZ/go-libp2p-pubsub-router"
5253
connmgr "gx/ipfs/QmV4Z9ufnVy7tMFHfBnoxbbAxDwFfKNKWtZAbY4CHCp79W/go-libp2p-connmgr"
53-
mfs "gx/ipfs/QmV8mXUh1M9qztax7vVdL1Apuz4c1eJZC5YactGxaJfWom/go-mfs"
5454
bserv "gx/ipfs/QmVDTbzzTwnuBwNbJdhW3u7LoBQp46bezm9yp4z1RoEepM/go-blockservice"
5555
resolver "gx/ipfs/QmVi2uUygezqaMTqs3Yzt5FcZFHJoYD4B7jQ2BELjj7ZuY/go-path/resolver"
5656
libp2p "gx/ipfs/QmVvV8JQmmqPCwXAaesWJPheUiEFQJ9HWRhWhuFuxVQxpR/go-libp2p"

‎core/coreapi/unixfs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
1212
"github.com/ipfs/go-ipfs/core/coreunix"
1313

14+
mfs "gx/ipfs/QmQr1qYm6Ww3ePruqLs2QhSZAHHsW2CzePNTEp48AT3Mg1/go-mfs"
1415
bstore "gx/ipfs/QmS2aqUZLJp8kF1ihE5rvDGE5LvmKDPnx32w9Z1BW9xLV5/go-ipfs-blockstore"
1516
ft "gx/ipfs/QmUnHNqhSB1JgzVCxL1Kz3yb4bdyB4q1Z9AD5AUBVmt3fZ/go-unixfs"
1617
uio "gx/ipfs/QmUnHNqhSB1JgzVCxL1Kz3yb4bdyB4q1Z9AD5AUBVmt3fZ/go-unixfs/io"
17-
mfs "gx/ipfs/QmV8mXUh1M9qztax7vVdL1Apuz4c1eJZC5YactGxaJfWom/go-mfs"
1818
blockservice "gx/ipfs/QmVDTbzzTwnuBwNbJdhW3u7LoBQp46bezm9yp4z1RoEepM/go-blockservice"
1919
cidutil "gx/ipfs/QmVjZoEZg2oxXGFGjbD28x3gGN6ALHAW6BN2LKRUcaJ21i/go-cidutil"
2020
offline "gx/ipfs/QmYZwey1thDTynSrvd6qQkX24UpTka6TFhQ2v569UpoqxD/go-ipfs-exchange-offline"

‎core/corerepo/gc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
repo "github.com/ipfs/go-ipfs/repo"
1212

1313
humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
14+
mfs "gx/ipfs/QmQr1qYm6Ww3ePruqLs2QhSZAHHsW2CzePNTEp48AT3Mg1/go-mfs"
1415
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
15-
mfs "gx/ipfs/QmV8mXUh1M9qztax7vVdL1Apuz4c1eJZC5YactGxaJfWom/go-mfs"
1616
logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log"
1717
)
1818

‎core/coreunix/add.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
1515
"github.com/ipfs/go-ipfs/pin"
1616

17+
mfs "gx/ipfs/QmQr1qYm6Ww3ePruqLs2QhSZAHHsW2CzePNTEp48AT3Mg1/go-mfs"
1718
chunker "gx/ipfs/QmR4QQVkBZsZENRjYFVi8dEtPL3daZRNKk24m4r6WKJHNm/go-ipfs-chunker"
1819
posinfo "gx/ipfs/QmR6YMs8EkXQLXNwQKxLnQp2VBZSepoEJ8KCZAyanJHhJu/go-ipfs-posinfo"
1920
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
@@ -22,7 +23,6 @@ import (
2223
balanced "gx/ipfs/QmUnHNqhSB1JgzVCxL1Kz3yb4bdyB4q1Z9AD5AUBVmt3fZ/go-unixfs/importer/balanced"
2324
ihelper "gx/ipfs/QmUnHNqhSB1JgzVCxL1Kz3yb4bdyB4q1Z9AD5AUBVmt3fZ/go-unixfs/importer/helpers"
2425
trickle "gx/ipfs/QmUnHNqhSB1JgzVCxL1Kz3yb4bdyB4q1Z9AD5AUBVmt3fZ/go-unixfs/importer/trickle"
25-
mfs "gx/ipfs/QmV8mXUh1M9qztax7vVdL1Apuz4c1eJZC5YactGxaJfWom/go-mfs"
2626
apicid "gx/ipfs/QmVjZoEZg2oxXGFGjbD28x3gGN6ALHAW6BN2LKRUcaJ21i/go-cidutil/apicid"
2727
files "gx/ipfs/QmZMWMvWMVKCbHetJ4RgndbuEF1io2UpUxwQwtNjtYPzSC/go-ipfs-files"
2828
dag "gx/ipfs/QmcGt25mrjuB2kKW2zhPbXVZNHc4yoTDQ65NA8m6auP2f1/go-merkledag"

‎fuse/ipns/ipns_unix.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import (
1818
dag "gx/ipfs/QmcGt25mrjuB2kKW2zhPbXVZNHc4yoTDQ65NA8m6auP2f1/go-merkledag"
1919

2020
ci "gx/ipfs/QmNiJiXwWE3kRhZrC5ej3kSjWHm337pYfhjLGSCDNKJP2s/go-libp2p-crypto"
21+
mfs "gx/ipfs/QmQr1qYm6Ww3ePruqLs2QhSZAHHsW2CzePNTEp48AT3Mg1/go-mfs"
2122
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
2223
fuse "gx/ipfs/QmSJBsmLP1XMjv8hxYg2rUMdPDB7YUpyBo9idjrJ6Cmq6F/fuse"
2324
fs "gx/ipfs/QmSJBsmLP1XMjv8hxYg2rUMdPDB7YUpyBo9idjrJ6Cmq6F/fuse/fs"
24-
mfs "gx/ipfs/QmV8mXUh1M9qztax7vVdL1Apuz4c1eJZC5YactGxaJfWom/go-mfs"
2525
peer "gx/ipfs/QmcqU6QUDSXprb1518vYDGczrTJTyGwLG9eUa5iNX4xUtS/go-libp2p-peer"
2626
logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log"
2727
)

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,9 @@
530530
},
531531
{
532532
"author": "hsanjuan",
533-
"hash": "QmV8mXUh1M9qztax7vVdL1Apuz4c1eJZC5YactGxaJfWom",
533+
"hash": "QmQr1qYm6Ww3ePruqLs2QhSZAHHsW2CzePNTEp48AT3Mg1",
534534
"name": "go-mfs",
535-
"version": "0.1.25"
535+
"version": "0.1.26"
536536
},
537537
{
538538
"author": "kevina",

‎test/sharness/t0250-files-api.sh

+19
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ test_files_api() {
202202
test_cmp ls_l_expected ls_l_actual
203203
'
204204

205+
test_expect_success "file has correct hash and size listed with -l --cid-base=base32" '
206+
echo "file1 `cid-fmt -v 1 -b base32 %s $FILE1` 4" > ls_l_expected &&
207+
ipfs files ls --cid-base=base32 -l /cats/file1 > ls_l_actual &&
208+
test_cmp ls_l_expected ls_l_actual
209+
'
210+
205211
test_expect_success "file shows up with the correct name" '
206212
echo "file1" > ls_l_expected &&
207213
ipfs files ls /cats/file1 > ls_l_actual &&
@@ -221,6 +227,19 @@ test_files_api() {
221227
test_cmp file1stat_expect file1stat_actual
222228
'
223229

230+
test_expect_success "can stat file with --cid-base=base32 $EXTRA" '
231+
ipfs files stat --cid-base=base32 /cats/file1 > file1stat_orig
232+
'
233+
234+
test_expect_success "stat output looks good with --cid-base=base32" '
235+
grep -v CumulativeSize: file1stat_orig > file1stat_actual &&
236+
echo `cid-fmt -v 1 -b base32 %s $FILE1` > file1stat_expect &&
237+
echo "Size: 4" >> file1stat_expect &&
238+
echo "ChildBlocks: 0" >> file1stat_expect &&
239+
echo "Type: file" >> file1stat_expect &&
240+
test_cmp file1stat_expect file1stat_actual
241+
'
242+
224243
test_expect_success "can read file $EXTRA" '
225244
ipfs files read /cats/file1 > file1out
226245
'

0 commit comments

Comments
 (0)
Please sign in to comment.