Commit 6db29c0a authored by Kevin Atkinson's avatar Kevin Atkinson

Use constants for SHARDING and _README file names.

parent 9d9fdda1
......@@ -43,7 +43,7 @@ type ShardFunc func(string) string
var (
ErrDatastoreExists = errors.New("datastore already exist")
ErrDatastoreDoesNotExist = errors.New("datastore directory does not exist")
ErrShardingFileMissing = errors.New("SHARDING file not found in datastore")
ErrShardingFileMissing = fmt.Errorf("%s file not found in datastore", SHARDING_FN)
)
const IPFS_DEF_SHARD = "/repo/flatfs/shard/v1/next-to-last/2"
......@@ -68,7 +68,7 @@ func Create(path string, funStr string) error {
return err
}
if !isEmpty {
return fmt.Errorf("directory missing SHARDING file: %s", path)
return fmt.Errorf("directory missing %s file: %s", SHARDING_FN, path)
}
err = WriteShardFunc(path, fun)
......
......@@ -183,9 +183,9 @@ func testStorage(p *params, t *testing.T) {
return err
}
switch path {
case ".", "..", "SHARDING":
case ".", "..", flatfs.SHARDING_FN:
// ignore
case "_README":
case flatfs.README_FN:
_, err := ioutil.ReadFile(absPath)
if err != nil {
t.Error("could not read _README file")
......@@ -487,7 +487,7 @@ func TestNoCluster(t *testing.T) {
tolerance := math.Floor(idealFilesPerDir * 0.20)
count := 0
for _, dir := range dirs {
if dir.Name() == "SHARDING" {
if dir.Name() == flatfs.SHARDING_FN || dir.Name() == flatfs.README_FN {
continue
}
count += 1
......
......@@ -16,6 +16,8 @@ type ShardIdV1 struct {
}
const PREFIX = "/repo/flatfs/shard/"
const SHARDING_FN = "SHARDING"
const README_FN = "README"
func (f *ShardIdV1) String() string {
return fmt.Sprintf("%sv1/%s/%d", PREFIX, f.funName, f.param)
......@@ -72,7 +74,7 @@ func ParseShardFunc(str string) (*ShardIdV1, error) {
}
func ReadShardFunc(dir string) (*ShardIdV1, error) {
buf, err := ioutil.ReadFile(filepath.Join(dir, "SHARDING"))
buf, err := ioutil.ReadFile(filepath.Join(dir, SHARDING_FN))
if os.IsNotExist(err) {
return nil, ErrShardingFileMissing
} else if err != nil {
......@@ -82,7 +84,7 @@ func ReadShardFunc(dir string) (*ShardIdV1, error) {
}
func WriteShardFunc(dir string, id *ShardIdV1) error {
file, err := os.Create(filepath.Join(dir, "SHARDING"))
file, err := os.Create(filepath.Join(dir, SHARDING_FN))
if err != nil {
return err
}
......@@ -97,7 +99,7 @@ func WriteShardFunc(dir string, id *ShardIdV1) error {
func WriteReadme(dir string, id *ShardIdV1) error {
if id.String() == IPFS_DEF_SHARD {
err := ioutil.WriteFile(filepath.Join(dir, "_README"), []byte(README_IPFS_DEF_SHARD), 0444)
err := ioutil.WriteFile(filepath.Join(dir, README_FN), []byte(README_IPFS_DEF_SHARD), 0444)
if err != nil {
return err
}
......
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