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-ds-flatfs
Commits
ef9568aa
Commit
ef9568aa
authored
Jan 05, 2017
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add _README file when shard func is "v1/next-to-last/2"
parent
e89d36bd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
1 deletion
+49
-1
flatfs_test.go
flatfs_test.go
+13
-1
readme.go
readme.go
+30
-0
shard.go
shard.go
+6
-0
No files found.
flatfs_test.go
View file @
ef9568aa
...
...
@@ -175,6 +175,7 @@ func testStorage(p *params, t *testing.T) {
}
seen
:=
false
haveREADME
:=
false
walk
:=
func
(
absPath
string
,
fi
os
.
FileInfo
,
err
error
)
error
{
if
err
!=
nil
{
return
err
...
...
@@ -186,6 +187,12 @@ func testStorage(p *params, t *testing.T) {
switch
path
{
case
"."
,
".."
,
"SHARDING"
:
// ignore
case
"_README"
:
_
,
err
:=
ioutil
.
ReadFile
(
absPath
)
if
err
!=
nil
{
t
.
Error
(
"could not read _README file"
)
}
haveREADME
=
true
case
p
.
dir
:
if
!
fi
.
IsDir
()
{
t
.
Errorf
(
"%s directory is not a file? %v"
,
p
.
what
,
fi
.
Mode
())
...
...
@@ -213,6 +220,11 @@ func testStorage(p *params, t *testing.T) {
if
!
seen
{
t
.
Error
(
"did not see the data file"
)
}
if
fs
.
ShardFunc
()
==
flatfs
.
IPFS_DEF_SHARD
&&
!
haveREADME
{
t
.
Error
(
"expected _README file"
)
}
else
if
fs
.
ShardFunc
()
!=
flatfs
.
IPFS_DEF_SHARD
&&
haveREADME
{
t
.
Error
(
"did not expect _README file"
)
}
}
func
TestStorage
(
t
*
testing
.
T
)
{
...
...
@@ -405,7 +417,7 @@ func TestSHARDINGFile(t *testing.T) {
tempdir
,
cleanup
:=
tempdir
(
t
)
defer
cleanup
()
fun
:=
"next-to-last/2"
fun
:=
flatfs
.
IPFS_DEF_SHARD
fs
,
err
:=
flatfs
.
New
(
tempdir
,
fun
,
false
)
if
err
!=
nil
{
...
...
readme.go
0 → 100644
View file @
ef9568aa
package
flatfs
var
README_IPFS_DEF_SHARD
=
`This is a repository of IPLD objects. Each IPLD object is in a single file,
named <base32 encoding of cid>.data. Where <base32 encoding of cid> is the
"base32" encoding of the CID (as specified in
https://github.com/multiformats/multibase) without the 'B' prefix.
All the object files are placed in a tree of directories, based on a
function of the CID. This is a form of sharding similar to
the objects directory in git repositories. Previously, we used
prefixes, we now use the next-to-last two charters.
func NextToLast(base32cid string) {
nextToLastLen := 2
offset := len(base32cid) - nextToLastLen - 1
return str[offset : offset+nextToLastLen]
}
For example, an object with a CIDv1 of
BAFKREIA22FLID5AJ2KU7URG47MDLROZIH6YF2KALU2PWEFPVI37YLKRSCA
Will be placed at
SC/AFKREIA22FLID5AJ2KU7URG47MDLROZIH6YF2KALU2PWEFPVI37YLKRSCA.data
with 'SC' being the last-to-next two characters and the 'B' at the
beginning of the CIDv1 string is the multibase prefix that is not
stored in the filename.
`
shard.go
View file @
ef9568aa
...
...
@@ -104,6 +104,12 @@ func WriteShardFunc(dir, str string) error {
if
err
!=
nil
{
return
err
}
if
str
==
IPFS_DEF_SHARD
{
err
:=
ioutil
.
WriteFile
(
filepath
.
Join
(
dir
,
"_README"
),
[]
byte
(
README_IPFS_DEF_SHARD
),
0444
)
if
err
!=
nil
{
return
err
}
}
return
nil
}
...
...
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