Skip to content

Commit

Permalink
Merge pull request #17 from TRON-US/unixfs-get-repairs
Browse files Browse the repository at this point in the history
BTFS-1103 BTFS-1009: Add repairs (hashes) to unixfs get options
  • Loading branch information
taiyangc authored Dec 16, 2019
2 parents 8aa4888 + 922852d commit 68a18f4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
7 changes: 0 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETFUpAzWW2ep1Y=
github.com/Stebalien/go-bitfield v0.0.1/go.mod h1:GNjFpasyUVkHMsfEOk8EFLJ9syQ6SI+XWrX9Wf2XH0s=
github.com/TRON-US/go-btfs-chunker v0.2.0 h1:dp80UzRmUFzDDDt4nqo2STGVh5I4jDQJRYJYtRGulSo=
github.com/TRON-US/go-btfs-chunker v0.2.0/go.mod h1:6wFL7KgEumsn7R7IGFZZhOGIHxA/YkA4RdfR553M3Fk=
github.com/TRON-US/go-btfs-chunker v0.2.2 h1:aiLDsiM3X2Yy2jVo3EQYYEVkw57SThOUPTs0Ja5yPeA=
github.com/TRON-US/go-btfs-chunker v0.2.2/go.mod h1:Wj0oyybAWtu5lpcAc90QQ3bhJ14JRXD50PqxP25wmnI=
github.com/TRON-US/go-btfs-files v0.1.1 h1:GuDIiWDM66bfhfxJy8+dBL4Cfbcp3iBp7pgHpKKCw8k=
github.com/TRON-US/go-btfs-files v0.1.1/go.mod h1:tD2vOKLcLCDNMn9rrA27n2VbNpHdKewGzEguIFY+EJ0=
github.com/TRON-US/go-unixfs v0.4.1 h1:Vo1qIr8HT5D2GlfXaLG1lMrHq4plUyl1udIkCdVuF5U=
github.com/TRON-US/go-unixfs v0.4.1/go.mod h1:h/I7boDSgPi4Kw6qD/VJKQA62/+Lt+Zvb4nMRO57R1c=
github.com/TRON-US/go-unixfs v0.4.3-dev/go.mod h1:KJOb8DrNKJH9cdufqZba8ljdt3/vyo0KwfWNtwTzZbQ=
github.com/TRON-US/go-unixfs v0.4.4 h1:EzTr7aHrB/vlAr4onYb/ENdsFt0NYNUGAefVD93r28w=
github.com/TRON-US/go-unixfs v0.4.4/go.mod h1:VBRlISp23R6JoJQ2t+O/VkIswnPo9PBVCh5blMpN0GI=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
Expand Down Expand Up @@ -116,8 +111,6 @@ github.com/ipfs/go-ipfs-exchange-interface v0.0.1 h1:LJXIo9W7CAmugqI+uofioIpRb6r
github.com/ipfs/go-ipfs-exchange-interface v0.0.1/go.mod h1:c8MwfHjtQjPoDyiy9cFquVtVHkO9b9Ob3FG91qJnWCM=
github.com/ipfs/go-ipfs-exchange-offline v0.0.1 h1:P56jYKZF7lDDOLx5SotVh5KFxoY6C81I1NSHW1FxGew=
github.com/ipfs/go-ipfs-exchange-offline v0.0.1/go.mod h1:WhHSFCVYX36H/anEKQboAzpUws3x7UeEGkzQc3iNkM0=
github.com/ipfs/go-ipfs-files v0.0.3 h1:ME+QnC3uOyla1ciRPezDW0ynQYK2ikOh9OCKAEg4uUA=
github.com/ipfs/go-ipfs-files v0.0.3/go.mod h1:INEFm0LL2LWXBhNJ2PMIIb2w45hpXgPjNoE7yA8Y1d4=
github.com/ipfs/go-ipfs-flags v0.0.1 h1:OH5cEkJYL0QgA+bvD55TNG9ud8HA2Nqaav47b2c/UJk=
github.com/ipfs/go-ipfs-flags v0.0.1/go.mod h1:RnXBb9WV53GSfTrSDVK61NLTFKvWc60n+K9EgCDh+rA=
github.com/ipfs/go-ipfs-posinfo v0.0.1 h1:Esoxj+1JgSjX0+ylc0hUmJCOv6V2vFoZiETLR6OtpRs=
Expand Down
46 changes: 32 additions & 14 deletions options/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,25 @@ type UnixfsAddSettings struct {
type UnixfsGetSettings struct {
Decrypt bool
PrivateKey string
Metadata bool
Repairs []cid.Cid
}

type UnixfsLsSettings struct {
ResolveChildren bool
}

type UnixfsAddMetaSettings struct {
Pin bool
Overwrite bool
Events chan<- interface{}
Silent bool
Pin bool
Overwrite bool
Events chan<- interface{}
Silent bool
}

type UnixfsRemoveMetaSettings struct {
Pin bool
Events chan<- interface{}
Silent bool
Pin bool
Events chan<- interface{}
Silent bool
}

type UnixfsAddOption func(*UnixfsAddSettings) error
Expand Down Expand Up @@ -156,6 +158,8 @@ func UnixfsGetOptions(opts ...UnixfsGetOption) (*UnixfsGetSettings, error) {
options := &UnixfsGetSettings{
Decrypt: false,
PrivateKey: "",
Metadata: false,
Repairs: nil,
}
for _, opt := range opts {
err := opt(options)
Expand Down Expand Up @@ -183,9 +187,9 @@ func UnixfsLsOptions(opts ...UnixfsLsOption) (*UnixfsLsSettings, error) {

func UnixfsAddMetaOptions(opts ...UnixfsAddMetaOption) (*UnixfsAddMetaSettings, error) {
options := &UnixfsAddMetaSettings{
Pin: false,
Events: nil,
Silent: false,
Pin: false,
Events: nil,
Silent: false,
Overwrite: false,
}

Expand All @@ -201,9 +205,9 @@ func UnixfsAddMetaOptions(opts ...UnixfsAddMetaOption) (*UnixfsAddMetaSettings,

func UnixfsRemoveMetaOptions(opts ...UnixfsRemoveMetaOption) (*UnixfsRemoveMetaSettings, error) {
options := &UnixfsRemoveMetaSettings{
Pin: false,
Events: nil,
Silent: false,
Pin: false,
Events: nil,
Silent: false,
}

for _, opt := range opts {
Expand Down Expand Up @@ -251,6 +255,20 @@ func (unixfsOpts) PrivateKey(privateKey string) UnixfsGetOption {
}
}

func (unixfsOpts) Metadata(metadata bool) UnixfsGetOption {
return func(settings *UnixfsGetSettings) error {
settings.Metadata = metadata
return nil
}
}

func (unixfsOpts) Repairs(repairs []cid.Cid) UnixfsGetOption {
return func(settings *UnixfsGetSettings) error {
settings.Repairs = repairs
return nil
}
}

type unixfsOpts struct{}

var Unixfs unixfsOpts
Expand Down Expand Up @@ -439,4 +457,4 @@ func (unixfsOpts) PinToRemove(pin bool) UnixfsRemoveMetaOption {
settings.Pin = pin
return nil
}
}
}
5 changes: 2 additions & 3 deletions unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"github.com/TRON-US/interface-go-btfs-core/options"
path "github.com/TRON-US/interface-go-btfs-core/path"

"github.com/TRON-US/go-btfs-files"
"github.com/ipfs/go-cid"
)
Expand Down Expand Up @@ -71,8 +71,7 @@ type UnixfsAPI interface {
//
// Note that some implementations of this API may apply the specified context
// to operations performed on the returned file.
// The bool parameter indicates whether token metadata should be returned.
Get(context.Context, path.Path, bool, ...options.UnixfsGetOption) (files.Node, error)
Get(context.Context, path.Path, ...options.UnixfsGetOption) (files.Node, error)

// GetMetadata returns full metadata bytes within a UnixFS file referenced by path.
// If metadata is not available, it returns an error.
Expand Down

0 comments on commit 68a18f4

Please sign in to comment.