From fe85bf97116dc844a808cbfcb1f439222f56131d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvan-=E6=AC=A7=E9=98=B3=E5=B8=86?= Date: Fri, 24 Mar 2023 11:44:32 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-91503=20=E4=BF=9D=E5=AD=98=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E9=A2=91=E7=B9=81=E6=8A=A5=E9=94=99=E9=94=81=E5=AE=9A?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E4=B8=8D=E4=B8=80=E8=87=B4=EF=BC=8C=E5=9C=A8?= =?UTF-8?q?=E8=BF=99=E4=B8=AA=E5=BC=B9=E7=AA=97=E5=8F=A6=E5=AD=98=E4=B8=BA?= =?UTF-8?q?=E4=B8=80=E5=AE=9A=E4=BC=9A=E5=A4=B1=E8=B4=A5=E3=80=82=20?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=88=9B=E5=BB=BA=E6=A8=A1=E6=9D=BF=E5=A4=87?= =?UTF-8?q?=E4=BB=BD=E6=96=87=E4=BB=B6=E6=97=B6=E7=9A=84=E9=94=81=E5=AE=9A?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BB=A5=E5=8F=8A=E9=94=81=E5=AE=9A?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/utils/TemplateUtils.java | 34 +++++++++++++------ .../worker/save/SaveFailureHandler.java | 2 +- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java b/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java index e7d3c3dca3..ce01d9992f 100644 --- a/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java +++ b/designer-base/src/main/java/com/fr/design/utils/TemplateUtils.java @@ -85,28 +85,42 @@ public class TemplateUtils { private static void createAndOpenTemplate0(FILE file, String oldPath, boolean createByEditingTemplate, boolean openNewTemplate, Runnable doAfterCreateTemplate) { - new SwingWorker() { + new SwingWorker() { @Override - protected Void doInBackground() throws Exception { + protected Boolean doInBackground() throws Exception { // 读取模板数据 byte[] content = getTemplateData(createByEditingTemplate, oldPath); - try (OutputStream out = file.asOutputStream()) { + OutputStream out = null; + try { // 加锁 - WorkContext.getCurrent().get(TplOperator.class).saveAs(file.getPath()); + boolean saveAsLock = WorkContext.getCurrent().get(TplOperator.class).saveAs(file.getPath()); + if (!saveAsLock) { + // 加锁失败时,直接返回 + return false; + } + out = file.asOutputStream(); out.write(content); } finally { - // 解锁 - WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(file.getPath()); + try { + if (out != null) { + out.close(); + } + } finally { + // 解锁 + WorkContext.getCurrent().get(TplOperator.class).closeAndFreeFile(file.getPath()); + } } - return null; + return true; } @Override protected void done() { try { - get(); - // 创建备份成功后 + if (!get()) { + throw new Exception("[RemoteDesign] back up template file failed"); + } + // 创建备份成功后,关闭原模板 doAfterCreateTemplate.run(); if (openNewTemplate) { DesignerContext.getDesignerFrame().openTemplate(file); @@ -126,7 +140,7 @@ public class TemplateUtils { * * @param readCurrentEditingTemplate 是否读取当前编辑模板 * @param path 模板路径 - * @return 模板文件数据 + * @return 模板文件数据 */ private static byte[] getTemplateData(boolean readCurrentEditingTemplate, String path) throws Exception { byte[] content = new byte[0]; diff --git a/designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java b/designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java index 128064301e..119668ec68 100644 --- a/designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java +++ b/designer-base/src/main/java/com/fr/design/worker/save/SaveFailureHandler.java @@ -139,7 +139,7 @@ public class SaveFailureHandler implements ThrowableHandler { new FileNodeFILE(new FileNode(template.getPath(), false)), true, true, - // 创建并打开备份模板后,关闭原模板 + // 创建并打开备份模板后,关闭原模板,无需释放原模板锁(锁定信息不一致 = 此用户模板锁信息已被清除) () -> HistoryTemplateListCache.getInstance().closeSelectedReport(template)); } }