From 755004e4d30a66ea2646c4ca91668f553fd1e834 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Fri, 21 Apr 2023 17:38:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=B4=A2=E5=BC=95=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E5=8A=A0=E8=BD=BD=E5=A4=B1=E8=B4=A5=E6=97=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=B0=9D=E8=AF=95=E9=87=8D=E5=BB=BA=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/list_file_db.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/internal/caches/list_file_db.go b/internal/caches/list_file_db.go index c4543e1..9392bff 100644 --- a/internal/caches/list_file_db.go +++ b/internal/caches/list_file_db.go @@ -226,6 +226,20 @@ func (this *FileListDB) Init() error { err := this.hashMap.Load(this) if err != nil { remotelogs.Error("LIST_FILE_DB", "load hash map failed: "+err.Error()+"(file: "+this.dbPath+")") + + // 自动修复错误 + // TODO 将来希望能尽可能恢复以往数据库中的内容 + if strings.Contains(err.Error(), "database is closed") || strings.Contains(err.Error(), "database disk image is malformed") { + _ = this.Close() + this.deleteDB() + remotelogs.Println("LIST_FILE_DB", "recreating the database (file:"+this.dbPath+") ...") + err = this.Open(this.dbPath) + if err != nil { + remotelogs.Error("LIST_FILE_DB", "recreate the database failed: "+err.Error()+" (file:"+this.dbPath+")") + } else { + _ = this.Init() + } + } } }() @@ -683,3 +697,10 @@ func (this *FileListDB) shouldRecover() bool { _ = result.Close() return shouldRecover } + +// 删除数据库文件 +func (this *FileListDB) deleteDB() { + _ = os.Remove(this.dbPath) + _ = os.Remove(this.dbPath + "-shm") + _ = os.Remove(this.dbPath + "-wal") +}