Skip to content

Commit

Permalink
🎨 If a file with the same name exists during export PDF/Docx, it will…
Browse files Browse the repository at this point in the history
… be automatically renamed #11357
  • Loading branch information
88250 committed May 19, 2024
1 parent f2c7bf2 commit c792380
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/appearance/langs/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@
"212": "There are some defects in the current version of cloud data sync, please upgrade to the latest version. Sorry for the inconvenience",
"213": "Cloud verification failed, please try to upgrade to the latest version and log in again before syncing",
"214": "This function needs to be signed in and purchasing [PRO Features] or [Subscription] to use",
"215": "Save failed: The target file is being used by another program",
"215": "TODO",
"216": "Rebuilding asset content data index, please wait...",
"217": "[%d/%d] Created asset content data index",
"218": "Too many snapshots of the data repo have been detected, which slows down program startup and data sync. Please consider executing [Settings - About - Data repo purge]",
Expand Down
2 changes: 1 addition & 1 deletion app/appearance/langs/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@
"212": "Hay algunos defectos en la versi\u00f3n actual de sincronizaci\u00f3n de datos en la nube, actualice a la versi\u00f3n m\u00e1s reciente. Disculpe las molestias",
"213": "La verificaci\u00f3n en la nube fall\u00f3, intente actualizar a la versi\u00f3n m\u00e1s reciente e inicie sesi\u00f3n de nuevo antes de sincronizar",
"214": "Esta función requiere iniciar sesión en su cuenta y comprar [PRO Features] o [Subscription] antes de poder usarla.",
"215": "Error al guardar: el archivo de destino está siendo utilizado por otro programa",
"215": "TODO",
"216": "Reconstruyendo el índice de datos de contenido de recursos, espere...",
"217": "[%d/%d] Índice de datos de contenido de activos creado",
"218": "Se han detectado demasiadas instantáneas del repositorio de datos, lo que ralentiza el inicio del programa y la sincronización de datos. Considere ejecutar [Configuración - Acerca de - Purga del repositorio de datos]",
Expand Down
2 changes: 1 addition & 1 deletion app/appearance/langs/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@
"212": "Il y a quelques défauts dans la version actuelle de la synchronisation des données cloud, veuillez mettre à niveau vers la dernière version. Désolé pour le désagrément",
"213": "Échec de la vérification cloud, veuillez essayer de mettre à niveau vers la dernière version et de vous reconnecter avant de synchroniser",
"214": "Cette fonction nécessite de vous connecter à votre compte et d'acheter des [PRO Features] ou un [Subscription] avant de pouvoir l'utiliser.",
"215": "Échec de l'enregistrement : le fichier de destination est utilisé par un autre programme",
"215": "TODO",
"216": "Reconstruction de l'index des données du contenu des ressources, veuillez patienter...",
"217": "[%d/%d] Création d'un index de données de contenu d'actif",
"218": "Trop d'instantanés du référentiel de données ont été détectés, ce qui ralentit le démarrage du programme et la synchronisation des données. Veuillez envisager d'exécuter [Paramètres - À propos - Purge du référentiel de données]",
Expand Down
2 changes: 1 addition & 1 deletion app/appearance/langs/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@
"212": "現在のバージョンのクラウドデータ同期にはいくつかの問題があります。最新バージョンにアップグレードしてください",
"213": "クラウド認証に失敗しました。最新バージョンにアップグレードしてから再度ログインして同期を試みてください",
"214": "この機能を使用するには、ログインして [PRO 機能] または [サブスクリプション] を購入する必要があります",
"215": "保存に失敗しました。対象ファイルが別のプログラムによって使用されています",
"215": "TODO",
"216": "アセットコンテンツデータインデックスを再構築しています。お待ちください...",
"217": "[%d/%d] アセットコンテンツデータインデックスを作成しました",
"218": "検出されたデータリポジトリのスナップショットが多すぎるため、プログラムの起動とデータ同期が遅くなります。[設定] - [情報] - [データリポジトリの消去] の実行を検討してください",
Expand Down
2 changes: 1 addition & 1 deletion app/appearance/langs/zh_CHT.json
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@
"212": "當前版本雲端數據同步存在一些缺陷,請升級到最新版,帶來不便,敬請諒解",
"213": "雲端校驗失敗,請嘗試升級到最新版並重新登錄後再進行同步",
"214": "此功能需要登入帳號併購買 [功能特性] 或 [年付訂閱] 後才能使用",
"215": "保存失敗:目標文件正在被其他程序佔用",
"215": "TODO",
"216": "正在重建資源文件內容數據索引,請稍等...",
"217": "[%d/%d] 已經創建資源文件內容數據索引",
"218": "偵測到資料倉儲快照過多,降低了程式啟動和資料同步速度,請考慮執行 [設定 - 關於 - 資料倉儲清理]",
Expand Down
2 changes: 1 addition & 1 deletion app/appearance/langs/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@
"212": "当前版本云端数据同步存在一些缺陷,请升级到最新版,带来不便,敬请谅解",
"213": "云端校验失败,请尝试升级到最新版并重新登录后再进行同步",
"214": "该功能需要登录账号并购买 [功能特性] 或者 [年付订阅] 后才能使用",
"215": "保存失败:目标文件并且正在被其他程序占用",
"215": "TODO",
"216": "正在重建资源文件内容数据索引,请稍等...",
"217": "[%d/%d] 已经创建资源文件内容数据索引",
"218": "检测到数据仓库快照过多,降低了程序启动和数据同步速度,请考虑执行 [设置 - 关于 - 数据仓库清理]",
Expand Down
31 changes: 14 additions & 17 deletions kernel/model/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,13 @@ func Preview(id string) (retStdHTML string, retOutline []*Path) {
return
}

func ExportDocx(id, savePath string, removeAssets, merge bool) (err error) {
func ExportDocx(id, savePath string, removeAssets, merge bool) (fullPath string, err error) {
if !util.IsValidPandocBin(Conf.Export.PandocBin) {
Conf.Export.PandocBin = util.PandocBinPath
Conf.Save()
if !util.IsValidPandocBin(Conf.Export.PandocBin) {
return errors.New(Conf.Language(115))
err = errors.New(Conf.Language(115))
return
}
}

Expand All @@ -587,7 +588,8 @@ func ExportDocx(id, savePath string, removeAssets, merge bool) (err error) {
if !gulu.File.IsExist(docxTemplate) {
logging.LogErrorf("docx template [%s] not found", docxTemplate)
msg := fmt.Sprintf(Conf.Language(197), docxTemplate)
return errors.New(msg)
err = errors.New(msg)
return
}

args = append(args, "--reference-doc", docxTemplate)
Expand All @@ -600,28 +602,23 @@ func ExportDocx(id, savePath string, removeAssets, merge bool) (err error) {
if nil != err {
logging.LogErrorf("export docx failed: %s", gulu.Str.FromBytes(output))
msg := fmt.Sprintf(Conf.Language(14), gulu.Str.FromBytes(output))
return errors.New(msg)
}

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)
}
err = errors.New(msg)
return
}

if err = filelock.Copy(tmpDocxPath, targetPath); nil != err {
fullPath = filepath.Join(savePath, name+".docx")
fullPath = util.GetUniqueFilename(fullPath)
if err = filelock.Copy(tmpDocxPath, fullPath); nil != err {
logging.LogErrorf("export docx failed: %s", err)
return errors.New(fmt.Sprintf(Conf.Language(14), err))
err = errors.New(fmt.Sprintf(Conf.Language(14), err))
return
}

if tmpAssets := filepath.Join(tmpDir, "assets"); !removeAssets && gulu.File.IsDir(tmpAssets) {
if err = filelock.Copy(tmpAssets, filepath.Join(savePath, "assets")); nil != err {
logging.LogErrorf("export docx failed: %s", err)
return errors.New(fmt.Sprintf(Conf.Language(14), err))
err = errors.New(fmt.Sprintf(Conf.Language(14), err))
return
}
}
return
Expand Down

0 comments on commit c792380

Please sign in to comment.