diff --git a/jOOQ-codegen/src/main/java/org/jooq/util/GeneratorWriter.java b/jOOQ-codegen/src/main/java/org/jooq/util/GeneratorWriter.java index a65c557bc7..7800c96fe4 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/util/GeneratorWriter.java +++ b/jOOQ-codegen/src/main/java/org/jooq/util/GeneratorWriter.java @@ -36,6 +36,7 @@ package org.jooq.util; import java.io.File; import java.io.FileOutputStream; +import java.io.FilenameFilter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; @@ -253,17 +254,31 @@ public abstract class GeneratorWriter> { // [#3756] Regenerate files only if there is a difference String oldContent = null; if (file.exists()) { - RandomAccessFile old = null; - try { - old = new RandomAccessFile(file, "r"); - byte[] oldBytes = new byte[(int) old.length()]; - old.readFully(oldBytes); - oldContent = new String(oldBytes, encoding()); - } - finally { - if (old != null) - old.close(); + // [#5892] On Windows FAT or NTFS and other case-insensitive file systems, we must + // explicitly replace files whose case-sensitive file name has changed + String[] list = file.getParentFile().list(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.equalsIgnoreCase(file.getName()) && !name.equals(file.getName()); + } + }); + + if (list != null && list.length > 0) + file.delete(); + else { + RandomAccessFile old = null; + + try { + old = new RandomAccessFile(file, "r"); + byte[] oldBytes = new byte[(int) old.length()]; + old.readFully(oldBytes); + oldContent = new String(oldBytes, encoding()); + } + finally { + if (old != null) + old.close(); + } } }