Commit ef9568aa authored by Kevin Atkinson's avatar Kevin Atkinson

Add _README file when shard func is "v1/next-to-last/2"

parent e89d36bd
......@@ -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 {
......
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.
`
......@@ -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
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment