Remove unfinished write transactions

parent 5274262c
......@@ -4,10 +4,12 @@
package flatfs
import (
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/query"
......@@ -110,8 +112,38 @@ func Move(oldPath string, newPath string, out io.Writer) error {
if err != nil {
return err
}
if inf.IsDir() || fn == SHARDING_FN || fn == README_FN {
// we are an empty directory or generated file so just remove it
if inf.IsDir() {
indir, err := os.Open(oldPath)
if err != nil {
return err
}
defer indir.Close()
names, err := indir.Readdirnames(-1)
if err != nil {
return err
}
for _, n := range names {
p := filepath.Join(oldPath, n)
// part of unfinished write transaction
// remove it
if strings.HasPrefix(n, "put-") {
err := os.Remove(p)
if err != nil {
return err
}
} else {
return errors.New("unknown file in flatfs: " + p)
}
}
err = os.Remove(oldPath)
if err != nil {
return err
}
} else if fn == SHARDING_FN || fn == README_FN {
// generated file so just remove it
err := os.Remove(oldPath)
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