2014-08-04 21:25:58 +00:00
|
|
|
package main
|
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
import "github.com/fd0/khepri/backend"
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
// func fsck_tree(be backend.Server, id backend.ID) (bool, error) {
|
|
|
|
// log.Printf(" checking dir %s", id)
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
// buf, err := be.GetBlob(id)
|
|
|
|
// if err != nil {
|
|
|
|
// return false, err
|
|
|
|
// }
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
// tree := &khepri.Tree{}
|
|
|
|
// err = json.Unmarshal(buf, tree)
|
|
|
|
// if err != nil {
|
|
|
|
// return false, err
|
|
|
|
// }
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
// if !id.Equal(backend.IDFromData(buf)) {
|
|
|
|
// return false, nil
|
|
|
|
// }
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
// return true, nil
|
|
|
|
// }
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
// func fsck_snapshot(be backend.Server, id backend.ID) (bool, error) {
|
|
|
|
// log.Printf("checking snapshot %s", id)
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
// sn, err := khepri.LoadSnapshot(be, id)
|
|
|
|
// if err != nil {
|
|
|
|
// return false, err
|
|
|
|
// }
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
// return fsck_tree(be, sn.Content)
|
|
|
|
// }
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
func commandFsck(be backend.Server, args []string) error {
|
|
|
|
// var snapshots backend.IDs
|
|
|
|
// var err error
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
// if len(args) != 0 {
|
|
|
|
// snapshots = make(backend.IDs, 0, len(args))
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
// for _, arg := range args {
|
|
|
|
// id, err := backend.ParseID(arg)
|
|
|
|
// if err != nil {
|
|
|
|
// log.Fatal(err)
|
|
|
|
// }
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
// snapshots = append(snapshots, id)
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// snapshots, err = be.ListRefs()
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
// if err != nil {
|
|
|
|
// log.Fatalf("error reading list of snapshot IDs: %v", err)
|
|
|
|
// }
|
|
|
|
// }
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
// log.Printf("checking %d snapshots", len(snapshots))
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
// for _, id := range snapshots {
|
|
|
|
// ok, err := fsck_snapshot(be, id)
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
// if err != nil {
|
|
|
|
// log.Printf("error checking snapshot %s: %v", id, err)
|
|
|
|
// continue
|
|
|
|
// }
|
2014-08-04 21:25:58 +00:00
|
|
|
|
2014-09-23 20:39:12 +00:00
|
|
|
// if !ok {
|
|
|
|
// log.Printf("snapshot %s failed", id)
|
|
|
|
// }
|
|
|
|
// }
|
2014-08-04 21:25:58 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|