From 2b6925af62061f233d45c0c11babc38535adf079 Mon Sep 17 00:00:00 2001 From: dp524856 <1456887752@qq.com> Date: Fri, 23 Aug 2019 02:38:37 +0800 Subject: [PATCH] add rebuild --- opt/options.go | 13 +------------ storage/migration.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/opt/options.go b/opt/options.go index 4cb2656..b874257 100644 --- a/opt/options.go +++ b/opt/options.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "math" "math/bits" + // "unsafe" // "github.com/ethereum/go-ethereum/common" @@ -131,18 +132,6 @@ func ParseConfig(fileName string) (*Options, error) { // SaveConfig saves config to file. func SaveConfig(config *Options, fileName string) error { - //file, err := os.Create(fileName) - //if err != nil { - // return err - //} - // - //defer file.Close() - //data, err := json.MarshalIndent(config, " ", "") - //n, err := file.Write(data) - //if n != len(data) || err != nil { - // return err - //} - //file.Sync() return nil } diff --git a/storage/migration.go b/storage/migration.go index d353872..98a1a76 100644 --- a/storage/migration.go +++ b/storage/migration.go @@ -2,6 +2,7 @@ package storage import ( "fmt" + "github.com/yottachain/YTFS/common" "github.com/yottachain/YTFS/opt" ) @@ -37,6 +38,21 @@ func (ti *TableIterator) GetTable() (common.IndexTable, error) { return table, nil } +func (ti *TableIterator) GetNoNilTable() (common.IndexTable, error) { + for { + table, err := ti.GetTable() + if err != nil { + return nil, err + } + if table == nil { + panic(fmt.Errorf("index.db文件已损坏,无法恢复")) + } + if len(table) > 0 { + return table, nil + } + } +} + func (ti *TableIterator) Reset() { ti.tableIndex = 0 } -- GitLab