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-dms3
Commits
f2fbfdf2
Commit
f2fbfdf2
authored
Aug 16, 2017
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mfs: inherit CID prefix from from parent directory
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
parent
77e9b8dd
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
40 additions
and
7 deletions
+40
-7
core/commands/files/files.go
core/commands/files/files.go
+2
-0
mfs/dir.go
mfs/dir.go
+6
-0
mfs/file.go
mfs/file.go
+8
-3
mfs/ops.go
mfs/ops.go
+6
-2
test/sharness/t0260-sharding-flag.sh
test/sharness/t0260-sharding-flag.sh
+2
-2
unixfs/hamt/hamt.go
unixfs/hamt/hamt.go
+7
-0
unixfs/io/dirbuilder.go
unixfs/io/dirbuilder.go
+9
-0
No files found.
core/commands/files/files.go
View file @
f2fbfdf2
...
...
@@ -890,8 +890,10 @@ func getFileHandle(r *mfs.Root, path string, create bool) (*mfs.File, error) {
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"%s was not a directory"
,
dirname
)
}
prefix
:=
pdir
.
GetPrefix
()
nd
:=
dag
.
NodeWithData
(
ft
.
FilePBData
(
nil
,
0
))
nd
.
SetPrefix
(
prefix
)
err
=
pdir
.
AddChild
(
fname
,
nd
)
if
err
!=
nil
{
return
nil
,
err
...
...
mfs/dir.go
View file @
f2fbfdf2
...
...
@@ -58,6 +58,11 @@ func NewDirectory(ctx context.Context, name string, node node.Node, parent child
},
nil
}
// GetPrefix gets the CID prefix of the root node
func
(
d
*
Directory
)
GetPrefix
()
*
cid
.
Prefix
{
return
d
.
dirbuilder
.
GetPrefix
()
}
// SetPrefix sets the CID prefix
func
(
d
*
Directory
)
SetPrefix
(
prefix
*
cid
.
Prefix
)
{
d
.
dirbuilder
.
SetPrefix
(
prefix
)
...
...
@@ -299,6 +304,7 @@ func (d *Directory) Mkdir(name string) (*Directory, error) {
}
ndir
:=
ft
.
EmptyDirNode
()
ndir
.
SetPrefix
(
d
.
GetPrefix
())
_
,
err
=
d
.
dserv
.
Add
(
ndir
)
if
err
!=
nil
{
...
...
mfs/file.go
View file @
f2fbfdf2
...
...
@@ -27,14 +27,19 @@ type File struct {
RawLeaves
bool
}
// NewFile returns a NewFile object with the given parameters
// NewFile returns a NewFile object with the given parameters. If the
// Cid version is non-zero RawLeaves will be enabled.
func
NewFile
(
name
string
,
node
node
.
Node
,
parent
childCloser
,
dserv
dag
.
DAGService
)
(
*
File
,
error
)
{
return
&
File
{
fi
:=
&
File
{
dserv
:
dserv
,
parent
:
parent
,
name
:
name
,
node
:
node
,
},
nil
}
if
node
.
Cid
()
.
Prefix
()
.
Version
>
0
{
fi
.
RawLeaves
=
true
}
return
fi
,
nil
}
const
(
...
...
mfs/ops.go
View file @
f2fbfdf2
...
...
@@ -129,7 +129,9 @@ func Mkdir(r *Root, pth string, mkparents bool, flush bool) error {
if
err
!=
nil
{
return
err
}
mkd
.
SetPrefix
(
r
.
Prefix
)
if
r
.
Prefix
!=
nil
{
mkd
.
SetPrefix
(
r
.
Prefix
)
}
fsn
=
mkd
}
else
if
err
!=
nil
{
return
err
...
...
@@ -148,7 +150,9 @@ func Mkdir(r *Root, pth string, mkparents bool, flush bool) error {
return
err
}
}
final
.
SetPrefix
(
r
.
Prefix
)
if
r
.
Prefix
!=
nil
{
final
.
SetPrefix
(
r
.
Prefix
)
}
if
flush
{
err
:=
final
.
Flush
()
...
...
test/sharness/t0260-sharding-flag.sh
View file @
f2fbfdf2
...
...
@@ -75,8 +75,8 @@ test_add_large_dir_v1() {
'
}
# this hash implies
both
the directory
and the
leaf entries are CIDv1
SHARDEDV1
=
"zdj7W
X91spg4DsnNpvoBLjyjXUGgcTTWavygBbSifpmJdgPUA
"
# this hash implies the directory
is CIDv1 and
leaf entries are CIDv1
and raw
SHARDEDV1
=
"zdj7W
Y8aNcxF49q1ZpFXfchNmbswnUxiVDVjmrHb53xRM8W4C
"
test_add_large_dir_v1
"
$SHARDEDV1
"
test_launch_ipfs_daemon
...
...
unixfs/hamt/hamt.go
View file @
f2fbfdf2
...
...
@@ -121,6 +121,7 @@ func NewHamtFromDag(dserv dag.DAGService, nd node.Node) (*HamtShard, error) {
ds
.
children
=
make
([]
child
,
len
(
pbnd
.
Links
()))
ds
.
bitfield
=
new
(
big
.
Int
)
.
SetBytes
(
pbd
.
GetData
())
ds
.
hashFunc
=
pbd
.
GetHashType
()
ds
.
prefix
=
&
ds
.
nd
.
Prefix
return
ds
,
nil
}
...
...
@@ -130,6 +131,11 @@ func (ds *HamtShard) SetPrefix(prefix *cid.Prefix) {
ds
.
prefix
=
prefix
}
// GetPrefix gets the CID Prefix, may be nil if unset
func
(
ds
*
HamtShard
)
Prefix
()
*
cid
.
Prefix
{
return
ds
.
prefix
}
// Node serializes the HAMT structure into a merkledag node with unixfs formatting
func
(
ds
*
HamtShard
)
Node
()
(
node
.
Node
,
error
)
{
out
:=
new
(
dag
.
ProtoNode
)
...
...
@@ -500,6 +506,7 @@ func (ds *HamtShard) modifyValue(ctx context.Context, hv *hashBits, key string,
if
err
!=
nil
{
return
err
}
ns
.
prefix
=
ds
.
prefix
chhv
:=
&
hashBits
{
b
:
hash
([]
byte
(
child
.
key
)),
consumed
:
hv
.
consumed
,
...
...
unixfs/io/dirbuilder.go
View file @
f2fbfdf2
...
...
@@ -115,6 +115,7 @@ func (d *Directory) switchToSharding(ctx context.Context) error {
if
err
!=
nil
{
return
err
}
s
.
SetPrefix
(
&
d
.
dirnode
.
Prefix
)
d
.
shard
=
s
for
_
,
lnk
:=
range
d
.
dirnode
.
Links
()
{
...
...
@@ -192,3 +193,11 @@ func (d *Directory) GetNode() (node.Node, error) {
return
d
.
shard
.
Node
()
}
func
(
d
*
Directory
)
GetPrefix
()
*
cid
.
Prefix
{
if
d
.
shard
==
nil
{
return
&
d
.
dirnode
.
Prefix
}
return
d
.
shard
.
Prefix
()
}
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