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
go-unixfs
Commits
06009a2f
Commit
06009a2f
authored
Sep 26, 2018
by
Overbool
Committed by
Lucas Molas
Sep 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(type): issue #23
parent
929f9a57
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
28 deletions
+31
-28
archive/tar/writer.go
archive/tar/writer.go
+5
-6
hamt/hamt.go
hamt/hamt.go
+2
-11
io/dagreader.go
io/dagreader.go
+4
-6
io/pbdagreader.go
io/pbdagreader.go
+3
-5
unixfs.go
unixfs.go
+17
-0
No files found.
archive/tar/writer.go
View file @
06009a2f
...
...
@@ -13,7 +13,6 @@ import (
mdag
"github.com/ipfs/go-merkledag"
ft
"github.com/ipfs/go-unixfs"
uio
"github.com/ipfs/go-unixfs/io"
upb
"github.com/ipfs/go-unixfs/pb"
ipld
"github.com/ipfs/go-ipld-format"
)
...
...
@@ -79,15 +78,15 @@ func (w *Writer) WriteNode(nd ipld.Node, fpath string) error {
}
switch
fsNode
.
Type
()
{
case
upb
.
Data_
Metadata
:
case
ft
.
T
Metadata
:
fallthrough
case
upb
.
Data_
Directory
,
upb
.
Data_
HAMTShard
:
case
ft
.
T
Directory
,
ft
.
T
HAMTShard
:
return
w
.
writeDir
(
nd
,
fpath
)
case
upb
.
Data_
Raw
:
case
ft
.
T
Raw
:
fallthrough
case
upb
.
Data_
File
:
case
ft
.
T
File
:
return
w
.
writeFile
(
nd
,
fsNode
,
fpath
)
case
upb
.
Data_
Symlink
:
case
ft
.
T
Symlink
:
return
writeSymlinkHeader
(
w
.
TarW
,
string
(
fsNode
.
Data
()),
fpath
)
default
:
return
ft
.
ErrUnrecognizedType
...
...
hamt/hamt.go
View file @
06009a2f
...
...
@@ -27,10 +27,7 @@ import (
dag
"github.com/ipfs/go-merkledag"
format
"github.com/ipfs/go-unixfs"
upb
"github.com/ipfs/go-unixfs/pb"
bitfield
"github.com/Stebalien/go-bitfield"
proto
"github.com/gogo/protobuf/proto"
cid
"github.com/ipfs/go-cid"
ipld
"github.com/ipfs/go-ipld-format"
"github.com/spaolacci/murmur3"
...
...
@@ -108,7 +105,7 @@ func NewHamtFromDag(dserv ipld.DAGService, nd ipld.Node) (*Shard, error) {
}
if
fsn
.
Type
()
!=
upb
.
Data_
HAMTShard
{
if
fsn
.
Type
()
!=
format
.
T
HAMTShard
{
return
nil
,
fmt
.
Errorf
(
"node was not a dir shard"
)
}
...
...
@@ -176,13 +173,7 @@ func (ds *Shard) Node() (ipld.Node, error) {
cindex
++
}
typ
:=
upb
.
Data_HAMTShard
data
,
err
:=
proto
.
Marshal
(
&
upb
.
Data
{
Type
:
&
typ
,
Fanout
:
proto
.
Uint64
(
uint64
(
ds
.
tableSize
)),
HashType
:
proto
.
Uint64
(
HashMurmur3
),
Data
:
ds
.
bitfield
.
Bytes
(),
})
data
,
err
:=
format
.
HAMTShardData
(
ds
.
bitfield
.
Bytes
(),
uint64
(
ds
.
tableSize
),
HashMurmur3
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
io/dagreader.go
View file @
06009a2f
...
...
@@ -7,8 +7,6 @@ import (
mdag
"github.com/ipfs/go-merkledag"
ft
"github.com/ipfs/go-unixfs"
ftpb
"github.com/ipfs/go-unixfs/pb"
ipld
"github.com/ipfs/go-ipld-format"
)
...
...
@@ -49,12 +47,12 @@ func NewDagReader(ctx context.Context, n ipld.Node, serv ipld.NodeGetter) (DagRe
}
switch
fsNode
.
Type
()
{
case
ft
pb
.
Data_
Directory
,
ft
pb
.
Data_
HAMTShard
:
case
ft
.
T
Directory
,
ft
.
T
HAMTShard
:
// Dont allow reading directories
return
nil
,
ErrIsDir
case
ft
pb
.
Data_File
,
ftpb
.
Data_
Raw
:
case
ft
.
TFile
,
ft
.
T
Raw
:
return
NewPBFileReader
(
ctx
,
n
,
fsNode
,
serv
),
nil
case
ft
pb
.
Data_
Metadata
:
case
ft
.
T
Metadata
:
if
len
(
n
.
Links
())
==
0
{
return
nil
,
errors
.
New
(
"incorrectly formatted metadata object"
)
}
...
...
@@ -68,7 +66,7 @@ func NewDagReader(ctx context.Context, n ipld.Node, serv ipld.NodeGetter) (DagRe
return
nil
,
mdag
.
ErrNotProtobuf
}
return
NewDagReader
(
ctx
,
childpb
,
serv
)
case
ft
pb
.
Data_
Symlink
:
case
ft
.
T
Symlink
:
return
nil
,
ErrCantReadSymlinks
default
:
return
nil
,
ft
.
ErrUnrecognizedType
...
...
io/pbdagreader.go
View file @
06009a2f
...
...
@@ -8,8 +8,6 @@ import (
mdag
"github.com/ipfs/go-merkledag"
ft
"github.com/ipfs/go-unixfs"
ftpb
"github.com/ipfs/go-unixfs/pb"
cid
"github.com/ipfs/go-cid"
ipld
"github.com/ipfs/go-ipld-format"
)
...
...
@@ -134,10 +132,10 @@ func (dr *PBDagReader) loadBufNode(node ipld.Node) error {
}
switch
fsNode
.
Type
()
{
case
ft
pb
.
Data_
File
:
case
ft
.
T
File
:
dr
.
buf
=
NewPBFileReader
(
dr
.
ctx
,
node
,
fsNode
,
dr
.
serv
)
return
nil
case
ft
pb
.
Data_
Raw
:
case
ft
.
T
Raw
:
dr
.
buf
=
NewBufDagReader
(
fsNode
.
Data
())
return
nil
default
:
...
...
@@ -318,7 +316,7 @@ func (dr *PBDagReader) Seek(offset int64, whence int) (int64, error) {
// for this seems to be good(-enough) solution as it's only returned by
// precalcNextBuf when we step out of file range.
// This is needed for gateway to function properly
if
err
==
io
.
EOF
&&
dr
.
file
.
Type
()
==
ft
pb
.
Data_
File
{
if
err
==
io
.
EOF
&&
dr
.
file
.
Type
()
==
ft
.
T
File
{
return
-
1
,
nil
}
return
n
,
err
...
...
unixfs.go
View file @
06009a2f
...
...
@@ -106,6 +106,23 @@ func SymlinkData(path string) ([]byte, error) {
return
out
,
nil
}
// HAMTShardData return a `Data_HAMTShard` protobuf message
func
HAMTShardData
(
data
[]
byte
,
fanout
uint64
,
hashType
uint64
)
([]
byte
,
error
)
{
pbdata
:=
new
(
pb
.
Data
)
typ
:=
pb
.
Data_HAMTShard
pbdata
.
Type
=
&
typ
pbdata
.
HashType
=
proto
.
Uint64
(
hashType
)
pbdata
.
Data
=
data
pbdata
.
Fanout
=
proto
.
Uint64
(
fanout
)
out
,
err
:=
proto
.
Marshal
(
pbdata
)
if
err
!=
nil
{
return
nil
,
err
}
return
out
,
nil
}
// UnwrapData unmarshals a protobuf messages and returns the contents.
func
UnwrapData
(
data
[]
byte
)
([]
byte
,
error
)
{
pbdata
:=
new
(
pb
.
Data
)
...
...
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