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
34826257
Unverified
Commit
34826257
authored
Mar 07, 2019
by
Steven Allen
Committed by
GitHub
Mar 07, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14 from ipfs/feat/nicer-ls
tweak the Ls interface
parents
4714c85c
4ba2c7db
Pipeline
#35
failed with stages
in 0 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
32 deletions
+72
-32
.gx/lastpubver
.gx/lastpubver
+1
-1
package.json
package.json
+1
-1
tests/unixfs.go
tests/unixfs.go
+33
-16
unixfs.go
unixfs.go
+37
-14
No files found.
.gx/lastpubver
View file @
34826257
0.1.1
1
: Qm
XLwxifxwfc2bAwq6rdjbYqAsGzWsDE9RM5TWMGtykyj6
0.1.1
2
: Qm
Y1veddRDFZZBUFp2Mysw7mf2sSmbx1ZGH5v11tTMCYN5
package.json
View file @
34826257
...
@@ -91,6 +91,6 @@
...
@@ -91,6 +91,6 @@
"license"
:
""
,
"license"
:
""
,
"name"
:
"interface-go-ipfs-core"
,
"name"
:
"interface-go-ipfs-core"
,
"releaseCmd"
:
"git commit -a -m
\"
gx publish $VERSION
\"
"
,
"releaseCmd"
:
"git commit -a -m
\"
gx publish $VERSION
\"
"
,
"version"
:
"0.1.1
1
"
"version"
:
"0.1.1
2
"
}
}
tests/unixfs.go
View file @
34826257
...
@@ -737,39 +737,56 @@ func (tp *provider) TestLs(t *testing.T) {
...
@@ -737,39 +737,56 @@ func (tp *provider) TestLs(t *testing.T) {
defer cancel()
defer cancel()
api, err := tp.makeAPI(ctx)
api, err := tp.makeAPI(ctx)
if err != nil {
if err != nil {
t.
Error
(err)
t.
Fatal
(err)
}
}
r := strings.NewReader("content-of-file")
r := strings.NewReader("content-of-file")
p, err := api.Unixfs().Add(ctx, files.NewMapDirectory(map[string]files.Node{
p, err := api.Unixfs().Add(ctx, files.NewMapDirectory(map[string]files.Node{
"0": files.NewMapDirectory(map[string]files.Node{
"0": files.NewMapDirectory(map[string]files.Node{
"name-of-file": files.NewReaderFile(r),
"name-of-file": files.NewReaderFile(r),
"name-of-symlink": files.NewLinkFile("/foo/bar", nil),
}),
}),
}))
}))
if err != nil {
if err != nil {
t.
Error
(err)
t.
Fatal
(err)
}
}
link
s, err := api.Unixfs().Ls(ctx, p)
entrie
s, err := api.Unixfs().Ls(ctx, p)
if err != nil {
if err != nil {
t.
Error
(err)
t.
Fatal
(err)
}
}
linkRes := <-link
s
entry := <-entrie
s
if
linkRes
.Err != nil {
if
entry
.Err != nil {
t.Fatal(
linkRes
.Err)
t.Fatal(
entry
.Err)
}
}
link := linkRes.Link
if entry.Size != 15 {
if linkRes.Size != 15 {
t.Errorf("expected size = 15, got %d", entry.Size)
t.Fatalf("expected size = 15, got %d", link.Size)
}
}
if
link
.Name != "name-of-file" {
if
entry
.Name != "name-of-file" {
t.
Fatal
f("expected name = name-of-file, got %s",
link
.Name)
t.
Error
f("expected name = name-of-file, got %s",
entry
.Name)
}
}
if
link.Cid.String() != "QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr"
{
if
entry.Type != coreiface.TFile
{
t.
Fatalf("expected cid = QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr, got %s", link.Cid
)
t.
Errorf("wrong type %s", entry.Type
)
}
}
if l, ok := <-links; ok {
if entry.Cid.String() != "QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr" {
t.Errorf("expected cid = QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr, got %s", entry.Cid)
}
entry = <-entries
if entry.Err != nil {
t.Fatal(entry.Err)
}
if entry.Type != coreiface.TSymlink {
t.Errorf("wrong type %s", entry.Type)
}
if entry.Name != "name-of-symlink" {
t.Errorf("expected name = name-of-symlink, got %s", entry.Name)
}
if entry.Target != "/foo/bar" {
t.Errorf("expected symlink target to be /foo/bar, got %s", entry.Target)
}
if l, ok := <-entries; ok {
t.Errorf("didn't expect a second link")
t.Errorf("didn't expect a second link")
if l.Err != nil {
if l.Err != nil {
t.Error(l.Err)
t.Error(l.Err)
...
...
unixfs.go
View file @
34826257
...
@@ -4,9 +4,8 @@ import (
...
@@ -4,9 +4,8 @@ import (
"context"
"context"
"github.com/ipfs/interface-go-ipfs-core/options"
"github.com/ipfs/interface-go-ipfs-core/options"
"github.com/ipfs/go-ipfs-files"
cid
"github.com/ipfs/go-cid"
ipld
"github.com/ipfs/go-ipld-format"
files
"github.com/ipfs/go-ipfs-files"
"github.com/ipfs/go-unixfs"
)
)
type
AddEvent
struct
{
type
AddEvent
struct
{
...
@@ -16,21 +15,45 @@ type AddEvent struct {
...
@@ -16,21 +15,45 @@ type AddEvent struct {
Size
string
`json:",omitempty"`
Size
string
`json:",omitempty"`
}
}
// FileType is an enum of possible UnixFS file types.
type
FileType
int32
type
FileType
int32
const
(
const
(
TRaw
=
FileType
(
unixfs
.
TRaw
)
// TUnknown means the file type isn't known (e.g., it hasn't been
TFile
=
FileType
(
unixfs
.
TFile
)
// resolved).
TDirectory
=
FileType
(
unixfs
.
TDirectory
)
TUnknown
FileType
=
iota
TMetadata
=
FileType
(
unixfs
.
TMetadata
)
// TFile is a regular file.
TSymlink
=
FileType
(
unixfs
.
TSymlink
)
TFile
THAMTShard
=
FileType
(
unixfs
.
THAMTShard
)
// TDirectory is a directory.
TDirectory
// TSymlink is a symlink.
TSymlink
)
)
type
LsLink
struct
{
func
(
t
FileType
)
String
()
string
{
Link
*
ipld
.
Link
switch
t
{
Size
uint64
case
TUnknown
:
Type
FileType
return
"unknown"
case
TFile
:
return
"file"
case
TDirectory
:
return
"directory"
case
TSymlink
:
return
"symlink"
default
:
return
"<unknown file type>"
}
}
// DirEntry is a directory entry returned by `Ls`.
type
DirEntry
struct
{
Name
string
Cid
cid
.
Cid
// Only filled when asked to resolve the directory entry.
Size
uint64
// The size of the file in bytes (or the size of the symlink).
Type
FileType
// The type of the file.
Target
string
// The symlink target (if a symlink).
Err
error
Err
error
}
}
...
@@ -51,5 +74,5 @@ type UnixfsAPI interface {
...
@@ -51,5 +74,5 @@ type UnixfsAPI interface {
// Ls returns the list of links in a directory. Links aren't guaranteed to be
// Ls returns the list of links in a directory. Links aren't guaranteed to be
// returned in order
// returned in order
Ls
(
context
.
Context
,
Path
,
...
options
.
UnixfsLsOption
)
(
<-
chan
LsLink
,
error
)
Ls
(
context
.
Context
,
Path
,
...
options
.
UnixfsLsOption
)
(
<-
chan
DirEntry
,
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