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
a92a1745
Commit
a92a1745
authored
Dec 14, 2018
by
Łukasz Magiera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
files2.0: return errors from ufsIterator properly
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
351ed26b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
4 deletions
+78
-4
core/coreapi/unixfile.go
core/coreapi/unixfile.go
+31
-4
core/coreapi/unixfs_test.go
core/coreapi/unixfs_test.go
+47
-0
No files found.
core/coreapi/unixfile.go
View file @
a92a1745
...
...
@@ -31,7 +31,8 @@ type ufsIterator struct {
curName
string
curFile
files
.
Node
err
error
err
error
errCh
chan
error
}
func
(
it
*
ufsIterator
)
Name
()
string
{
...
...
@@ -43,11 +44,31 @@ func (it *ufsIterator) Node() files.Node {
}
func
(
it
*
ufsIterator
)
Next
()
bool
{
l
,
ok
:=
<-
it
.
files
if
!
ok
{
if
it
.
err
!=
nil
{
return
false
}
var
l
*
ipld
.
Link
var
ok
bool
for
!
ok
{
if
it
.
files
==
nil
&&
it
.
errCh
==
nil
{
return
false
}
select
{
case
l
,
ok
=
<-
it
.
files
:
if
!
ok
{
it
.
files
=
nil
}
case
err
:=
<-
it
.
errCh
:
it
.
errCh
=
nil
it
.
err
=
err
if
err
!=
nil
{
return
false
}
}
}
it
.
curFile
=
nil
nd
,
err
:=
l
.
GetNode
(
it
.
ctx
,
it
.
dserv
)
...
...
@@ -71,8 +92,12 @@ func (d *ufsDirectory) Close() error {
func
(
d
*
ufsDirectory
)
Entries
()
files
.
DirIterator
{
fileCh
:=
make
(
chan
*
ipld
.
Link
,
prefetchFiles
)
errCh
:=
make
(
chan
error
,
1
)
go
func
()
{
d
.
dir
.
ForEachLink
(
d
.
ctx
,
func
(
link
*
ipld
.
Link
)
error
{
errCh
<-
d
.
dir
.
ForEachLink
(
d
.
ctx
,
func
(
link
*
ipld
.
Link
)
error
{
if
d
.
ctx
.
Err
()
!=
nil
{
return
d
.
ctx
.
Err
()
}
select
{
case
fileCh
<-
link
:
case
<-
d
.
ctx
.
Done
()
:
...
...
@@ -81,12 +106,14 @@ func (d *ufsDirectory) Entries() files.DirIterator {
return
nil
})
close
(
errCh
)
close
(
fileCh
)
}()
return
&
ufsIterator
{
ctx
:
d
.
ctx
,
files
:
fileCh
,
errCh
:
errCh
,
dserv
:
d
.
dserv
,
}
}
...
...
core/coreapi/unixfs_test.go
View file @
a92a1745
...
...
@@ -776,6 +776,53 @@ func TestLs(t *testing.T) {
}
}
func TestEntriesExpired(t *testing.T) {
ctx := context.Background()
node, api, err := makeAPI(ctx)
if err != nil {
t.Error(err)
}
r := strings.NewReader("content-of-file")
k, _, err := coreunix.AddWrapped(node, r, "name-of-file")
if err != nil {
t.Error(err)
}
parts := strings.Split(k, "/")
if len(parts) != 2 {
t.Errorf("unexpected path: %s", k)
}
p, err := coreiface.ParsePath("/ipfs/" + parts[0])
if err != nil {
t.Error(err)
}
ctx, cancel := context.WithCancel(ctx)
nd, err := api.Unixfs().Get(ctx, p)
if err != nil {
t.Error(err)
}
cancel()
it := files.ToDir(nd).Entries()
if it == nil {
t.Fatal("it was nil")
}
if it.Next() {
t.Fatal("Next succeeded")
}
if it.Err() != context.Canceled {
t.Fatalf("unexpected error %s", it.Err())
}
if it.Next() {
t.Fatal("Next succeeded")
}
}
func TestLsEmptyDir(t *testing.T) {
ctx := context.Background()
node, api, err := makeAPI(ctx)
...
...
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