Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
3003f938
Commit
3003f938
authored
Oct 19, 2017
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix "files stat" to work on raw nodes.
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
parent
0182e597
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
25 deletions
+46
-25
core/commands/files/files.go
core/commands/files/files.go
+33
-25
test/sharness/t0250-files-api.sh
test/sharness/t0250-files-api.sh
+13
-0
No files found.
core/commands/files/files.go
View file @
3003f938
...
...
@@ -168,38 +168,46 @@ func statNode(ds dag.DAGService, fsn mfs.FSNode) (*Object, error) {
c
:=
nd
.
Cid
()
pbnd
,
ok
:=
nd
.
(
*
dag
.
ProtoNode
)
if
!
ok
{
return
nil
,
dag
.
ErrNotProtobuf
}
d
,
err
:=
ft
.
FromBytes
(
pbnd
.
Data
())
if
err
!=
nil
{
return
nil
,
err
}
cumulsize
,
err
:=
nd
.
Size
()
if
err
!=
nil
{
return
nil
,
err
}
var
ndtype
string
switch
fsn
.
Type
()
{
case
mfs
.
TDir
:
ndtype
=
"directory"
case
mfs
.
TFile
:
ndtype
=
"file"
switch
n
:=
nd
.
(
type
)
{
case
*
dag
.
ProtoNode
:
d
,
err
:=
ft
.
FromBytes
(
n
.
Data
())
if
err
!=
nil
{
return
nil
,
err
}
var
ndtype
string
switch
fsn
.
Type
()
{
case
mfs
.
TDir
:
ndtype
=
"directory"
case
mfs
.
TFile
:
ndtype
=
"file"
default
:
return
nil
,
fmt
.
Errorf
(
"unrecognized node type: %s"
,
fsn
.
Type
())
}
return
&
Object
{
Hash
:
c
.
String
(),
Blocks
:
len
(
nd
.
Links
()),
Size
:
d
.
GetFilesize
(),
CumulativeSize
:
cumulsize
,
Type
:
ndtype
,
},
nil
case
*
dag
.
RawNode
:
return
&
Object
{
Hash
:
c
.
String
(),
Blocks
:
0
,
Size
:
cumulsize
,
CumulativeSize
:
cumulsize
,
Type
:
"file"
,
},
nil
default
:
return
nil
,
fmt
.
Errorf
(
"
Unrecognized node type: %s"
,
fsn
.
Type
()
)
return
nil
,
fmt
.
Errorf
(
"
not unixfs node (proto or raw)"
)
}
return
&
Object
{
Hash
:
c
.
String
(),
Blocks
:
len
(
nd
.
Links
()),
Size
:
d
.
GetFilesize
(),
CumulativeSize
:
cumulsize
,
Type
:
ndtype
,
},
nil
}
var
FilesCpCmd
=
&
cmds
.
Command
{
...
...
test/sharness/t0250-files-api.sh
View file @
3003f938
...
...
@@ -177,6 +177,19 @@ test_files_api() {
test_cmp ls_l_expected ls_l_actual
'
test_expect_success
"can stat file
$EXTRA
"
'
ipfs files stat /cats/file1 > file1stat_orig
'
test_expect_success
"stat output looks good"
'
grep -v CumulativeSize: file1stat_orig > file1stat_actual &&
echo "$FILE1" > file1stat_expect &&
echo "Size: 4" >> file1stat_expect &&
echo "ChildBlocks: 0" >> file1stat_expect &&
echo "Type: file" >> file1stat_expect &&
test_cmp file1stat_expect file1stat_actual
'
test_expect_success
"can read file
$EXTRA
"
'
ipfs files read /cats/file1 > file1out
'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment