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
af1aa24c
Unverified
Commit
af1aa24c
authored
Mar 22, 2019
by
Łukasz Magiera
Committed by
GitHub
Mar 22, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10 from ipfs/feat/add-wrap-fixes
Unixfs.Wrap Fixes
parents
55336c50
e12c21af
Pipeline
#37
failed with stages
in 0 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
113 deletions
+52
-113
options/unixfs.go
options/unixfs.go
+2
-23
tests/unixfs.go
tests/unixfs.go
+50
-90
No files found.
options/unixfs.go
View file @
af1aa24c
...
...
@@ -34,8 +34,6 @@ type UnixfsAddSettings struct {
NoCopy
bool
Wrap
bool
Hidden
bool
StdinName
string
Events
chan
<-
interface
{}
Silent
bool
...
...
@@ -68,8 +66,6 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix,
NoCopy
:
false
,
Wrap
:
false
,
Hidden
:
false
,
StdinName
:
""
,
Events
:
nil
,
Silent
:
false
,
...
...
@@ -247,23 +243,6 @@ func (unixfsOpts) Wrap(wrap bool) UnixfsAddOption {
}
}
// 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
}
}
// StdinName is the name set for files which don specify FilePath as
// os.Stdin.Name()
func
(
unixfsOpts
)
StdinName
(
name
string
)
UnixfsAddOption
{
return
func
(
settings
*
UnixfsAddSettings
)
error
{
settings
.
StdinName
=
name
return
nil
}
}
// Events specifies channel which will be used to report events about ongoing
// Add operation.
//
...
...
tests/unixfs.go
View file @
af1aa24c
...
...
@@ -82,12 +82,15 @@ func flatDir() files.Node {
})
}
func
wrapped
(
name
string
)
func
(
f
files
.
Node
)
files
.
Node
{
func
wrapped
(
name
s
...
string
)
func
(
f
files
.
Node
)
files
.
Node
{
return
func
(
f
files
.
Node
)
files
.
Node
{
return
files
.
NewMapDirectory
(
map
[
string
]
files
.
Node
{
name
:
f
,
for
i
:=
range
names
{
f
=
files
.
NewMapDirectory
(
map
[
string
]
files
.
Node
{
names
[
len
(
names
)
-
i
-
1
]
:
f
,
})
}
return
f
}
}
func
(
tp
*
provider
)
TestAdd
(
t
*
testing
.
T
)
{
...
...
@@ -240,17 +243,31 @@ func (tp *provider) TestAdd(t *testing.T) {
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
HashOnly
(
true
)},
},
// multi file
{
name
:
"simpleDirNoWrap"
,
data
:
flatDir
,
path
:
"/ipfs/QmRKGpFfR32FVXdvJiHfo4WJ5TDYBsM1P9raAp1p6APWSp"
,
},
{
name
:
"simpleDirWrap"
,
data
:
flatDir
,
expect
:
wrapped
(
"QmRKGpFfR32FVXdvJiHfo4WJ5TDYBsM1P9raAp1p6APWSp"
),
path
:
"/ipfs/QmXxCaQkC8Z6Qws1nTkTQfCsL9y4XvWXnrPokp9bhmjC1L"
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Wrap
(
true
)},
},
{
name
:
"simpleDir"
,
data
:
flatDir
,
wrap
:
"t"
,
path
:
"/ipfs/QmRKGpFfR32FVXdvJiHfo4WJ5TDYBsM1P9raAp1p6APWSp"
,
expect
:
wrapped
(
"t"
),
path
:
"/ipfs/Qmc3nGXm1HtUVCmnXLQHvWcNwfdZGpfg2SRm1CxLf7Q2Rm"
,
},
{
name
:
"twoLevelDir"
,
data
:
twoLevelDir
(),
wrap
:
"t"
,
path
:
"/ipfs/QmVG2ZYCkV1S4TK8URA3a4RupBF17A8yAr4FqsRDXVJASr"
,
expect
:
wrapped
(
"t"
),
path
:
"/ipfs/QmPwsL3T5sWhDmmAWZHAzyjKtMVDS9a11aHNRqb3xoVnmg"
,
},
// wrapped
{
...
...
@@ -261,15 +278,6 @@ func (tp *provider) TestAdd(t *testing.T) {
},
wrap
:
"foo"
,
expect
:
wrapped
(
"foo"
),
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Wrap
(
true
)},
},
{
name
:
"addNotWrappedDirFile"
,
path
:
hello
,
data
:
func
()
files
.
Node
{
return
files
.
NewBytesFile
([]
byte
(
helloStr
))
},
wrap
:
"foo"
,
},
{
name
:
"stdinWrapped"
,
...
...
@@ -284,43 +292,25 @@ func (tp *provider) TestAdd(t *testing.T) {
},
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Wrap
(
true
)},
},
{
name
:
"stdinNamed"
,
path
:
"/ipfs/QmQ6cGBmb3ZbdrQW1MRm1RJnYnaxCqfssz7CrTa9NEhQyS"
,
data
:
func
()
files
.
Node
{
rf
,
err
:=
files
.
NewReaderPathFile
(
os
.
Stdin
.
Name
(),
ioutil
.
NopCloser
(
strings
.
NewReader
(
helloStr
)),
nil
)
if
err
!=
nil
{
panic
(
err
)
}
return
rf
},
expect
:
func
(
files
.
Node
)
files
.
Node
{
return
files
.
NewMapDirectory
(
map
[
string
]
files
.
Node
{
"test"
:
files
.
NewBytesFile
([]
byte
(
helloStr
)),
})
},
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Wrap
(
true
),
options
.
Unixfs
.
StdinName
(
"test"
)},
},
{
name
:
"twoLevelDirWrapped"
,
data
:
twoLevelDir
(),
wrap
:
"t"
,
expect
:
wrapped
(
"t"
),
path
:
"/ipfs/Qm
PwsL3T5sWhDmmAWZHAzyjKtMVDS9a11aHNRqb3xoVnmg
"
,
expect
:
wrapped
(
"QmPwsL3T5sWhDmmAWZHAzyjKtMVDS9a11aHNRqb3xoVnmg"
,
"t"
),
path
:
"/ipfs/Qm
XzZwAh34pmNjuKsVGZfpbByis5S5qeZjCCUxa1ajZqzH
"
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Wrap
(
true
)},
},
{
name
:
"twoLevelInlineHash"
,
data
:
twoLevelDir
(),
wrap
:
"t"
,
expect
:
wrapped
(
"t"
),
path
:
"/ipfs/
zBunoruKoyCHKkALNSWxDvj4L7yuQnMgQ4hUa9j1Z64tVcDEcu6Zdetyu7eeFCxMPfxb7YJvHeFHoFoHMkBUQf6vfdhmi
"
,
expect
:
wrapped
(
"zBunoruKoyCHKkALNSWxDvj4L7yuQnMgQ4hUa9j1Z64tVcDEcu6Zdetyu7eeFCxMPfxb7YJvHeFHoFoHMkBUQf6vfdhmi"
,
"t"
),
path
:
"/ipfs/
QmUX6GykDGHTMtLmDkfjqs48QwQK82vou51xwaY9TSU7Zo
"
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Wrap
(
true
),
options
.
Unixfs
.
Inline
(
true
),
options
.
Unixfs
.
RawLeaves
(
true
),
options
.
Unixfs
.
Hash
(
mh
.
SHA3
)},
},
// hidden
{
name
:
"hiddenFiles"
,
name
:
"hiddenFiles
Added
"
,
data
:
func
()
files
.
Node
{
return
files
.
NewMapDirectory
(
map
[
string
]
files
.
Node
{
".bar"
:
files
.
NewBytesFile
([]
byte
(
"hello2"
)),
...
...
@@ -329,32 +319,8 @@ func (tp *provider) TestAdd(t *testing.T) {
})
},
wrap
:
"t"
,
path
:
"/ipfs/QmehGvpf2hY196MzDFmjL8Wy27S4jbgGDUAhBJyvXAwr3g"
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Hidden
(
true
)},
},
{
name
:
"hiddenFileAlwaysAdded"
,
data
:
func
()
files
.
Node
{
return
files
.
NewBytesFile
([]
byte
(
helloStr
))
},
wrap
:
".foo"
,
path
:
hello
,
},
{
name
:
"hiddenFilesNotAdded"
,
data
:
func
()
files
.
Node
{
return
files
.
NewMapDirectory
(
map
[
string
]
files
.
Node
{
".bar"
:
files
.
NewBytesFile
([]
byte
(
"hello2"
)),
"bar"
:
files
.
NewBytesFile
([]
byte
(
"hello2"
)),
"foo"
:
files
.
NewBytesFile
([]
byte
(
"hello1"
)),
})
},
expect
:
func
(
files
.
Node
)
files
.
Node
{
return
flatDir
()
},
wrap
:
"t"
,
path
:
"/ipfs/QmRKGpFfR32FVXdvJiHfo4WJ5TDYBsM1P9raAp1p6APWSp"
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Hidden
(
false
)},
expect
:
wrapped
(
"t"
),
path
:
"/ipfs/QmPXLSBX382vJDLrGakcbrZDkU3grfkjMox7EgSC9KFbtQ"
,
},
// NoCopy
{
...
...
@@ -392,10 +358,9 @@ func (tp *provider) TestAdd(t *testing.T) {
data
:
twoLevelDir
(),
path
:
"/ipfs/QmVG2ZYCkV1S4TK8URA3a4RupBF17A8yAr4FqsRDXVJASr"
,
events
:
[]
coreiface
.
AddEvent
{
{
Name
:
"
t/
abc"
,
Path
:
p
(
"QmU7nuGs2djqK99UNsNgEPGh6GV4662p6WtsgccBNGTDxt"
),
Size
:
"62"
},
{
Name
:
"
t
"
,
Path
:
p
(
"QmVG2ZYCkV1S4TK8URA3a4RupBF17A8yAr4FqsRDXVJASr"
),
Size
:
"229"
},
{
Name
:
"abc"
,
Path
:
p
(
"QmU7nuGs2djqK99UNsNgEPGh6GV4662p6WtsgccBNGTDxt"
),
Size
:
"62"
},
{
Name
:
""
,
Path
:
p
(
"QmVG2ZYCkV1S4TK8URA3a4RupBF17A8yAr4FqsRDXVJASr"
),
Size
:
"229"
},
},
wrap
:
"t"
,
opts
:
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Silent
(
true
)},
},
{
...
...
@@ -403,13 +368,12 @@ func (tp *provider) TestAdd(t *testing.T) {
data
:
twoLevelDir
(),
path
:
"/ipfs/QmVG2ZYCkV1S4TK8URA3a4RupBF17A8yAr4FqsRDXVJASr"
,
events
:
[]
coreiface
.
AddEvent
{
{
Name
:
"
t/
abc/def"
,
Path
:
p
(
"QmNyJpQkU1cEkBwMDhDNFstr42q55mqG5GE5Mgwug4xyGk"
),
Size
:
"13"
},
{
Name
:
"
t/
bar"
,
Path
:
p
(
"QmS21GuXiRMvJKHos4ZkEmQDmRBqRaF5tQS2CQCu2ne9sY"
),
Size
:
"14"
},
{
Name
:
"
t/
foo"
,
Path
:
p
(
"QmfAjGiVpTN56TXi6SBQtstit5BEw3sijKj1Qkxn6EXKzJ"
),
Size
:
"14"
},
{
Name
:
"
t/
abc"
,
Path
:
p
(
"QmU7nuGs2djqK99UNsNgEPGh6GV4662p6WtsgccBNGTDxt"
),
Size
:
"62"
},
{
Name
:
"
t
"
,
Path
:
p
(
"QmVG2ZYCkV1S4TK8URA3a4RupBF17A8yAr4FqsRDXVJASr"
),
Size
:
"229"
},
{
Name
:
"abc/def"
,
Path
:
p
(
"QmNyJpQkU1cEkBwMDhDNFstr42q55mqG5GE5Mgwug4xyGk"
),
Size
:
"13"
},
{
Name
:
"bar"
,
Path
:
p
(
"QmS21GuXiRMvJKHos4ZkEmQDmRBqRaF5tQS2CQCu2ne9sY"
),
Size
:
"14"
},
{
Name
:
"foo"
,
Path
:
p
(
"QmfAjGiVpTN56TXi6SBQtstit5BEw3sijKj1Qkxn6EXKzJ"
),
Size
:
"14"
},
{
Name
:
"abc"
,
Path
:
p
(
"QmU7nuGs2djqK99UNsNgEPGh6GV4662p6WtsgccBNGTDxt"
),
Size
:
"62"
},
{
Name
:
""
,
Path
:
p
(
"QmVG2ZYCkV1S4TK8URA3a4RupBF17A8yAr4FqsRDXVJASr"
),
Size
:
"229"
},
},
wrap
:
"t"
,
},
{
name
:
"progress1M"
,
...
...
@@ -528,14 +492,14 @@ func (tp *provider) TestAdd(t *testing.T) {
_
,
origDir
:=
orig
.
(
files
.
Directory
)
_
,
gotDir
:=
got
.
(
files
.
Directory
)
if
origDir
!=
gotDir
{
t
.
Fatal
(
"file type mismatch"
)
}
if
origName
!=
gotName
{
t
.
Errorf
(
"file name mismatch, orig='%s', got='%s'"
,
origName
,
gotName
)
}
if
origDir
!=
gotDir
{
t
.
Fatalf
(
"file type mismatch on %s"
,
origName
)
}
if
!
gotDir
{
defer
orig
.
Close
()
defer
got
.
Close
()
...
...
@@ -742,10 +706,8 @@ func (tp *provider) TestLs(t *testing.T) {
r
:=
strings
.
NewReader
(
"content-of-file"
)
p
,
err
:=
api
.
Unixfs
()
.
Add
(
ctx
,
files
.
NewMapDirectory
(
map
[
string
]
files
.
Node
{
"0"
:
files
.
NewMapDirectory
(
map
[
string
]
files
.
Node
{
"name-of-file"
:
files
.
NewReaderFile
(
r
),
"name-of-symlink"
:
files
.
NewLinkFile
(
"/foo/bar"
,
nil
),
}),
}))
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -804,9 +766,7 @@ func (tp *provider) TestEntriesExpired(t *testing.T) {
r
:=
strings
.
NewReader
(
"content-of-file"
)
p
,
err
:=
api
.
Unixfs
()
.
Add
(
ctx
,
files
.
NewMapDirectory
(
map
[
string
]
files
.
Node
{
"0"
:
files
.
NewMapDirectory
(
map
[
string
]
files
.
Node
{
"name-of-file"
:
files
.
NewReaderFile
(
r
),
}),
}))
if
err
!=
nil
{
t
.
Error
(
err
)
...
...
@@ -846,7 +806,7 @@ func (tp *provider) TestLsEmptyDir(t *testing.T) {
t
.
Error
(
err
)
}
_
,
err
=
api
.
Unixfs
()
.
Add
(
ctx
,
files
.
NewMapDirectory
(
map
[
string
]
files
.
Node
{
"0"
:
files
.
NewSliceDirectory
([]
files
.
DirEntry
{})
})
)
_
,
err
=
api
.
Unixfs
()
.
Add
(
ctx
,
files
.
NewSliceDirectory
([]
files
.
DirEntry
{}))
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
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