Skip to content

Commit

Permalink
coreapi: mirror unixfs file types
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <[email protected]>
  • Loading branch information
magik6k committed Feb 2, 2019
1 parent 1fef9a5 commit 6939b60
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
8 changes: 3 additions & 5 deletions core/commands/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
iface "github.com/ipfs/go-ipfs/core/coreapi/interface"
options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"

unixfs "gx/ipfs/QmQ1JnYpnzkaurjW1yxkQxC2w3K1PorNE1nv1vaP5Le7sq/go-unixfs"
unixfspb "gx/ipfs/QmQ1JnYpnzkaurjW1yxkQxC2w3K1PorNE1nv1vaP5Le7sq/go-unixfs/pb"
cmds "gx/ipfs/QmR77mMvvh8mJBBWQmBfQBu8oD38NUN4KE9SL2gDgAQNc6/go-ipfs-cmds"
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
)
Expand All @@ -21,7 +19,7 @@ import (
type LsLink struct {
Name, Hash string
Size uint64
Type unixfspb.Data_DataType
Type iface.FileType
}

// LsObject is an element of LsOutput
Expand Down Expand Up @@ -232,9 +230,9 @@ func tabularOutput(req *cmds.Request, w io.Writer, out *LsOutput, lastObjectHash
s := "%[1]s\t%[3]s\n"

switch {
case link.Type == unixfs.TDirectory && size:
case link.Type == iface.TDirectory && size:
s = "%[1]s\t-\t%[3]s/\n"
case link.Type == unixfs.TDirectory && !size:
case link.Type == iface.TDirectory && !size:
s = "%[1]s\t%[3]s/\n"
case size:
s = "%s\t%v\t%s\n"
Expand Down
15 changes: 13 additions & 2 deletions core/coreapi/interface/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"

"gx/ipfs/QmQ1JnYpnzkaurjW1yxkQxC2w3K1PorNE1nv1vaP5Le7sq/go-unixfs/pb"
"gx/ipfs/QmQ1JnYpnzkaurjW1yxkQxC2w3K1PorNE1nv1vaP5Le7sq/go-unixfs"
ipld "gx/ipfs/QmRL22E4paat7ky7vx9MLpR97JHHbFPrg3ytFQw6qp1y1s/go-ipld-format"
"gx/ipfs/QmaXvvAVAQ5ABqM5xtjYmV85xmN5MkWAZsX9H9Fwo4FVXp/go-ipfs-files"
)
Expand All @@ -16,10 +16,21 @@ type AddEvent struct {
Size string `json:",omitempty"`
}

type FileType int32

const (
TRaw = FileType(unixfs.TRaw)
TFile = FileType(unixfs.TFile)
TDirectory = FileType(unixfs.TDirectory)
TMetadata = FileType(unixfs.TMetadata)
TSymlink = FileType(unixfs.TSymlink)
THAMTShard = FileType(unixfs.THAMTShard)
)

type LsLink struct {
Link *ipld.Link
Size uint64
Type unixfs_pb.Data_DataType
Type FileType

Err error
}
Expand Down
4 changes: 2 additions & 2 deletions core/coreapi/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (api *UnixfsAPI) processLink(ctx context.Context, linkres ft.LinkResult, se
switch lnk.Link.Cid.Type() {
case cid.Raw:
// No need to check with raw leaves
lnk.Type = ft.TFile
lnk.Type = coreiface.TFile
lnk.Size = lnk.Link.Size
case cid.DagProtobuf:
if !settings.ResolveChildren {
Expand All @@ -201,7 +201,7 @@ func (api *UnixfsAPI) processLink(ctx context.Context, linkres ft.LinkResult, se
lnk.Err = err
break
}
lnk.Type = d.Type()
lnk.Type = coreiface.FileType(d.Type())
lnk.Size = d.FileSize()
}
}
Expand Down

0 comments on commit 6939b60

Please sign in to comment.