You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fesod.apache.org by "delei (via GitHub)" <gi...@apache.org> on 2026/10/08 15:31:47 UTC

Re: [PR] fix: reject same template and output file [fesod]

delei commented on code in PR #1163:
URL: https://github.com/apache/fesod/pull/1163#discussion_r4220954852


##########
fesod-sheet/src/main/java/org/apache/fesod/sheet/write/metadata/holder/WriteWorkbookHolder.java:
##########
@@ -273,6 +274,27 @@ public WriteWorkbookHolder(WriteWorkbook writeWorkbook) {
         this.dataFormatMap = MapUtils.newHashMap();
     }
 
+    private static void checkTemplateAndOutputFileAreDifferent(File outputFile, File templateFile) {
+        if (templateFile == null) {
+            return;
+        }
+        if (isSameFile(outputFile, templateFile)) {
+            throw new ExcelGenerateException("Template file and output file must be different.");
+        }
+    }
+
+    private static boolean isSameFile(File outputFile, File templateFile) {

Review Comment:
   Could we use `Files.isSameFile(...)` here? It’s a bit clearer and lets the file system handle same-file detection, including symlinks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org