From 81df7f262b34212698126a1f505421e539f6820b Mon Sep 17 00:00:00 2001 From: Minho Date: Mon, 2 Apr 2018 15:52:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9B=B4=E5=A4=9A=E7=9A=84?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/BookModel.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/models/BookModel.go b/models/BookModel.go index ef49a6cc..f03cab6c 100644 --- a/models/BookModel.go +++ b/models/BookModel.go @@ -279,6 +279,7 @@ func (book *Book) ThoroughDeleteBook(id int) error { if err != nil { o.Rollback() + return err } @@ -389,7 +390,7 @@ func (book *Book) ReleaseContent(bookId int) { _, err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("book_id", bookId).All(&docs, "document_id", "identify", "content") if err != nil { - beego.Error("发布失败 => ", err) + beego.Error("发布失败 =>",bookId, err) return } for _, item := range docs { @@ -441,7 +442,10 @@ func (book *Book) ReleaseContent(bookId int) { doc.RemoveCache() } - os.RemoveAll(filepath.Join(conf.WorkingDirectory, "uploads", "books", strconv.Itoa(bookId))) + if err := os.RemoveAll(filepath.Join(conf.WorkingDirectory, "uploads", "books", strconv.Itoa(bookId))); err != nil { + beego.Error("删除已缓存的文档目录失败 => ",filepath.Join(conf.WorkingDirectory, "uploads", "books", strconv.Itoa(bookId))) + } + } } } @@ -452,9 +456,12 @@ func (book *Book) ResetDocumentNumber(bookId int) { totalCount, err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("book_id", bookId).Count() if err == nil { - o.Raw("UPDATE md_books SET doc_count = ? WHERE book_id = ?", int(totalCount), bookId).Exec() + _,err = o.Raw("UPDATE md_books SET doc_count = ? WHERE book_id = ?", int(totalCount), bookId).Exec() + if err != nil { + beego.Error("重置文档数量失败 =>",bookId,err) + } } else { - beego.Error(err) + beego.Error("获取文档数量失败 =>",bookId,err) } } @@ -471,7 +478,9 @@ func (book *Book) ImportBook(zipPath string) error { tempPath := filepath.Join(os.TempDir(), md5str) - os.MkdirAll(tempPath, 0766) + if err := os.MkdirAll(tempPath, 0766); err != nil { + beego.Error("创建导入目录出错 => ",err) + } //如果加压缩失败 if err := ziptil.Unzip(zipPath, tempPath); err != nil { return err