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
interface-go-dms3-core
Commits
72006bfe
Commit
72006bfe
authored
Feb 01, 2019
by
Łukasz Magiera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coreapi: asunc ls option
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
93175e99
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
5 deletions
+53
-5
options/unixfs.go
options/unixfs.go
+30
-0
tests/unixfs.go
tests/unixfs.go
+20
-2
unixfs.go
unixfs.go
+3
-3
No files found.
options/unixfs.go
View file @
72006bfe
...
...
@@ -42,7 +42,12 @@ type UnixfsAddSettings struct {
Progress
bool
}
type
UnixfsLsSettings
struct
{
Async
bool
}
type
UnixfsAddOption
func
(
*
UnixfsAddSettings
)
error
type
UnixfsLsOption
func
(
*
UnixfsLsSettings
)
error
func
UnixfsAddOptions
(
opts
...
UnixfsAddOption
)
(
*
UnixfsAddSettings
,
cid
.
Prefix
,
error
)
{
options
:=
&
UnixfsAddSettings
{
...
...
@@ -122,6 +127,21 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix,
return
options
,
prefix
,
nil
}
func
UnixfsLsOptions
(
opts
...
UnixfsLsOption
)
(
*
UnixfsLsSettings
,
error
)
{
options
:=
&
UnixfsLsSettings
{
Async
:
true
,
}
for
_
,
opt
:=
range
opts
{
err
:=
opt
(
options
)
if
err
!=
nil
{
return
nil
,
err
}
}
return
options
,
nil
}
type
unixfsOpts
struct
{}
var
Unixfs
unixfsOpts
...
...
@@ -290,3 +310,13 @@ func (unixfsOpts) Nocopy(enable bool) UnixfsAddOption {
return
nil
}
}
// Async tells ls to return results as soon as they are available, which can be
// useful for listing HAMT directories. When this option is set to true returned
// results won't be returned in order
func
(
unixfsOpts
)
Async
(
async
bool
)
UnixfsLsOption
{
return
func
(
settings
*
UnixfsLsSettings
)
error
{
settings
.
Async
=
async
return
nil
}
}
tests/unixfs.go
View file @
72006bfe
...
...
@@ -749,12 +749,12 @@ func (tp *provider) TestLs(t *testing.T) {
t
.
Error
(
err
)
}
links
,
err
:=
api
.
Unixfs
()
.
Ls
(
ctx
,
p
)
links
,
err
:=
api
.
Unixfs
()
.
Ls
(
ctx
,
p
,
options
.
Unixfs
.
Async
(
false
)
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
link
:=
<-
links
link
:=
(
<-
links
)
.
Link
if
link
.
Size
!=
23
{
t
.
Fatalf
(
"expected size = 23, got %d"
,
link
.
Size
)
}
...
...
@@ -768,6 +768,24 @@ func (tp *provider) TestLs(t *testing.T) {
t
.
Errorf
(
"didn't expect a second link"
)
}
links
,
err
=
api
.
Unixfs
()
.
Ls
(
ctx
,
p
,
options
.
Unixfs
.
Async
(
true
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
link
=
(
<-
links
)
.
Link
if
link
.
Size
!=
23
{
t
.
Fatalf
(
"expected size = 23, got %d"
,
link
.
Size
)
}
if
link
.
Name
!=
"name-of-file"
{
t
.
Fatalf
(
"expected name = name-of-file, got %s"
,
link
.
Name
)
}
if
link
.
Cid
.
String
()
!=
"QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr"
{
t
.
Fatalf
(
"expected cid = QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr, got %s"
,
link
.
Cid
)
}
if
_
,
ok
:=
<-
links
;
ok
{
t
.
Errorf
(
"didn't expect a second link"
)
}
}
func
(
tp
*
provider
)
TestEntriesExpired
(
t
*
testing
.
T
)
{
...
...
unixfs.go
View file @
72006bfe
...
...
@@ -5,8 +5,8 @@ import (
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
ipld
"gx/ipfs/Qm
RL22E4paat7ky7vx9MLpR97JHHbFPrg3ytFQw6qp1y1s/go-ipld-format
"
files
"gx/ipfs/QmaXvvAVAQ5ABqM5xtjYmV85xmN5MkWAZsX9H9Fwo4FVXp/go-ipfs-files"
ft
"gx/ipfs/Qm
Q1JnYpnzkaurjW1yxkQxC2w3K1PorNE1nv1vaP5Le7sq/go-unixfs
"
"gx/ipfs/QmaXvvAVAQ5ABqM5xtjYmV85xmN5MkWAZsX9H9Fwo4FVXp/go-ipfs-files"
)
type
AddEvent
struct
{
...
...
@@ -31,5 +31,5 @@ type UnixfsAPI interface {
Get
(
context
.
Context
,
Path
)
(
files
.
Node
,
error
)
// Ls returns the list of links in a directory
Ls
(
context
.
Context
,
Path
)
(
<-
chan
*
ipld
.
Link
,
error
)
Ls
(
context
.
Context
,
Path
,
...
options
.
UnixfsLsOption
)
(
<-
chan
ft
.
LinkResult
,
error
)
}
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