🎨 Remove the target docx file when exporting Fix https://github.com/siyuan-note/siyuan/issues/8822

This commit is contained in:
Daniel 2023-07-26 16:56:40 +08:00
parent 5822d1f7af
commit bc36dc142a
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
6 changed files with 21 additions and 6 deletions

View file

@ -377,7 +377,17 @@ func ExportDocx(id, savePath string, removeAssets, merge bool) (err error) {
return errors.New(msg)
}
if err = filelock.Copy(tmpDocxPath, filepath.Join(savePath, name+".docx")); nil != err {
targetPath := filepath.Join(savePath, name+".docx")
if gulu.File.IsExist(targetPath) {
// 先删除目标文件,以检查是否被占用 https://github.com/siyuan-note/siyuan/issues/8822
if err := os.RemoveAll(targetPath); nil != err {
logging.LogErrorf("export docx failed: %s", err)
msg := fmt.Sprintf(Conf.language(215))
return errors.New(msg)
}
}
if err = filelock.Copy(tmpDocxPath, targetPath); nil != err {
logging.LogErrorf("export docx failed: %s", err)
return errors.New(fmt.Sprintf(Conf.Language(14), err))
}