Commit b02d206e authored by Kevin Atkinson's avatar Kevin Atkinson

Separate out writing Readme file into its own function.

Also use *ShardIdV1 instead of string for the shard fun parameter to
WriteShardFunc and WriteReadme.
parent f82967d9
......@@ -53,21 +53,23 @@ func Create(path string, funStr string) error {
return err
}
fun, err := ParseShardFunc(funStr)
if err != nil {
return err
}
dsFun, err := ReadShardFunc(path)
switch err {
case ShardingFileMissing:
// fixme: make sure directory is empty and return an error if
// it is not
err := WriteShardFunc(path, funStr)
err := WriteShardFunc(path, fun)
if err != nil {
return err
}
return nil
err = WriteReadme(path, fun)
return err
case nil:
fun, err := ParseShardFunc(funStr)
if err != nil {
return err
}
if fun.String() != dsFun.String() {
return fmt.Errorf("specified shard func '%s' does not match repo shard func '%s'",
fun.String(), dsFun.String())
......
......@@ -42,8 +42,8 @@ func ParseShardFunc(str string) (*ShardIdV1, error) {
if len(parts) != 2 {
return nil, fmt.Errorf("invalid shard identifier: %s", str)
}
id := &ShardIdV1 {funName: parts[0]}
id := &ShardIdV1{funName: parts[0]}
param, err := strconv.Atoi(parts[1])
if err != nil {
......@@ -75,11 +75,7 @@ func ReadShardFunc(dir string) (*ShardIdV1, error) {
return ParseShardFunc(string(buf))
}
func WriteShardFunc(dir, str string) error {
id, err := ParseShardFunc(str)
if err != nil {
return err
}
func WriteShardFunc(dir string, id *ShardIdV1) error {
file, err := os.Create(filepath.Join(dir, "SHARDING"))
if err != nil {
return err
......@@ -90,10 +86,11 @@ func WriteShardFunc(dir, str string) error {
return err
}
_, err = file.WriteString("\n")
if err != nil {
return err
}
if str == IPFS_DEF_SHARD {
return err
}
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)
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