Remove unfinished write transactions

parent 5274262c
...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
package flatfs package flatfs
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/query" "github.com/ipfs/go-datastore/query"
...@@ -110,8 +112,38 @@ func Move(oldPath string, newPath string, out io.Writer) error { ...@@ -110,8 +112,38 @@ func Move(oldPath string, newPath string, out io.Writer) error {
if err != nil { if err != nil {
return err return err
} }
if inf.IsDir() || fn == SHARDING_FN || fn == README_FN { if inf.IsDir() {
// we are an empty directory or generated file so just remove it 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) err := os.Remove(oldPath)
if err != nil { if err != nil {
return err 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