mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-21 19:50:56 +08:00
coreapi unixfs: hidden opiton
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
@ -33,6 +33,7 @@ type UnixfsAddSettings struct {
|
|||||||
Local bool
|
Local bool
|
||||||
|
|
||||||
Wrap bool
|
Wrap bool
|
||||||
|
Hidden bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type UnixfsAddOption func(*UnixfsAddSettings) error
|
type UnixfsAddOption func(*UnixfsAddSettings) error
|
||||||
@ -55,6 +56,7 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix,
|
|||||||
Local: false,
|
Local: false,
|
||||||
|
|
||||||
Wrap: false,
|
Wrap: false,
|
||||||
|
Hidden: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -215,3 +217,11 @@ func (unixfsOpts) Wrap(wrap bool) UnixfsAddOption {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hidden enables adding of hidden files (files prefixed with '.')
|
||||||
|
func (unixfsOpts) Hidden(hidden bool) UnixfsAddOption {
|
||||||
|
return func(settings *UnixfsAddSettings) error {
|
||||||
|
settings.Hidden = hidden
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -65,7 +65,7 @@ func (api *UnixfsAPI) Add(ctx context.Context, files files.File, opts ...options
|
|||||||
|
|
||||||
fileAdder.Chunker = settings.Chunker
|
fileAdder.Chunker = settings.Chunker
|
||||||
//fileAdder.Progress = progress
|
//fileAdder.Progress = progress
|
||||||
//fileAdder.Hidden = hidden
|
fileAdder.Hidden = settings.Hidden
|
||||||
fileAdder.Wrap = settings.Wrap
|
fileAdder.Wrap = settings.Wrap
|
||||||
fileAdder.Pin = settings.Pin && !settings.OnlyHash
|
fileAdder.Pin = settings.Pin && !settings.OnlyHash
|
||||||
fileAdder.Silent = true
|
fileAdder.Silent = true
|
||||||
|
@ -146,6 +146,12 @@ func twoLevelDir() func() files.File {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func wrapped(f files.File) files.File {
|
||||||
|
return files.NewSliceFile("", "", []files.File{
|
||||||
|
f,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAdd(t *testing.T) {
|
func TestAdd(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
_, api, err := makeAPI(ctx)
|
_, api, err := makeAPI(ctx)
|
||||||
@ -156,12 +162,12 @@ func TestAdd(t *testing.T) {
|
|||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
data func() files.File
|
data func() files.File
|
||||||
|
expect func(files.File) files.File
|
||||||
|
|
||||||
path string
|
path string
|
||||||
err string
|
err string
|
||||||
|
|
||||||
recursive bool
|
recursive bool
|
||||||
wrapped bool
|
|
||||||
|
|
||||||
opts []options.UnixfsAddOption
|
opts []options.UnixfsAddOption
|
||||||
}{
|
}{
|
||||||
@ -279,14 +285,14 @@ func TestAdd(t *testing.T) {
|
|||||||
data: func() files.File {
|
data: func() files.File {
|
||||||
return files.NewReaderFile("foo", "foo", ioutil.NopCloser(strings.NewReader(helloStr)), nil)
|
return files.NewReaderFile("foo", "foo", ioutil.NopCloser(strings.NewReader(helloStr)), nil)
|
||||||
},
|
},
|
||||||
wrapped: true,
|
expect: wrapped,
|
||||||
opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true)},
|
opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true)},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "twoLevelDirWrapped",
|
name: "twoLevelDirWrapped",
|
||||||
data: twoLevelDir(),
|
data: twoLevelDir(),
|
||||||
recursive: true,
|
recursive: true,
|
||||||
wrapped: true,
|
expect: wrapped,
|
||||||
path: "/ipfs/QmPwsL3T5sWhDmmAWZHAzyjKtMVDS9a11aHNRqb3xoVnmg",
|
path: "/ipfs/QmPwsL3T5sWhDmmAWZHAzyjKtMVDS9a11aHNRqb3xoVnmg",
|
||||||
opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true)},
|
opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true)},
|
||||||
},
|
},
|
||||||
@ -294,10 +300,51 @@ func TestAdd(t *testing.T) {
|
|||||||
name: "twoLevelInlineHash",
|
name: "twoLevelInlineHash",
|
||||||
data: twoLevelDir(),
|
data: twoLevelDir(),
|
||||||
recursive: true,
|
recursive: true,
|
||||||
wrapped: true,
|
expect: wrapped,
|
||||||
path: "/ipfs/zBunoruKoyCHKkALNSWxDvj4L7yuQnMgQ4hUa9j1Z64tVcDEcu6Zdetyu7eeFCxMPfxb7YJvHeFHoFoHMkBUQf6vfdhmi",
|
path: "/ipfs/zBunoruKoyCHKkALNSWxDvj4L7yuQnMgQ4hUa9j1Z64tVcDEcu6Zdetyu7eeFCxMPfxb7YJvHeFHoFoHMkBUQf6vfdhmi",
|
||||||
opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true), options.Unixfs.Inline(true), options.Unixfs.RawLeaves(true), options.Unixfs.Hash(mh.SHA3)},
|
opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true), options.Unixfs.Inline(true), options.Unixfs.RawLeaves(true), options.Unixfs.Hash(mh.SHA3)},
|
||||||
},
|
},
|
||||||
|
// hidden
|
||||||
|
{
|
||||||
|
name: "hiddenFiles",
|
||||||
|
data: func() files.File {
|
||||||
|
return files.NewSliceFile("t", "t", []files.File{
|
||||||
|
files.NewReaderFile("t/.bar", "t/.bar", ioutil.NopCloser(strings.NewReader("hello2")), nil),
|
||||||
|
files.NewReaderFile("t/bar", "t/bar", ioutil.NopCloser(strings.NewReader("hello2")), nil),
|
||||||
|
files.NewReaderFile("t/foo", "t/foo", ioutil.NopCloser(strings.NewReader("hello1")), nil),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
recursive: true,
|
||||||
|
path: "/ipfs/QmehGvpf2hY196MzDFmjL8Wy27S4jbgGDUAhBJyvXAwr3g",
|
||||||
|
opts: []options.UnixfsAddOption{options.Unixfs.Hidden(true)},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "hiddenFileAlwaysAdded",
|
||||||
|
data: func() files.File {
|
||||||
|
return files.NewReaderFile(".foo", ".foo", ioutil.NopCloser(strings.NewReader(helloStr)), nil)
|
||||||
|
},
|
||||||
|
recursive: true,
|
||||||
|
path: hello,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "hiddenFilesNotAdded",
|
||||||
|
data: func() files.File {
|
||||||
|
return files.NewSliceFile("t", "t", []files.File{
|
||||||
|
files.NewReaderFile("t/.bar", "t/.bar", ioutil.NopCloser(strings.NewReader("hello2")), nil),
|
||||||
|
files.NewReaderFile("t/bar", "t/bar", ioutil.NopCloser(strings.NewReader("hello2")), nil),
|
||||||
|
files.NewReaderFile("t/foo", "t/foo", ioutil.NopCloser(strings.NewReader("hello1")), nil),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
expect: func(files.File) files.File {
|
||||||
|
return files.NewSliceFile("t", "t", []files.File{
|
||||||
|
files.NewReaderFile("t/bar", "t/bar", ioutil.NopCloser(strings.NewReader("hello2")), nil),
|
||||||
|
files.NewReaderFile("t/foo", "t/foo", ioutil.NopCloser(strings.NewReader("hello1")), nil),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
recursive: true,
|
||||||
|
path: "/ipfs/QmRKGpFfR32FVXdvJiHfo4WJ5TDYBsM1P9raAp1p6APWSp",
|
||||||
|
opts: []options.UnixfsAddOption{options.Unixfs.Hidden(false)},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range cases {
|
for _, testCase := range cases {
|
||||||
@ -379,10 +426,8 @@ func TestAdd(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
orig := testCase.data()
|
orig := testCase.data()
|
||||||
if testCase.wrapped {
|
if testCase.expect != nil {
|
||||||
orig = files.NewSliceFile("", "", []files.File{
|
orig = testCase.expect(orig)
|
||||||
orig,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmpFile(orig, f)
|
cmpFile(orig, f)
|
||||||
|
Reference in New Issue
Block a user