[#5892] File does not get renamed on Windows when TABLE_A is renamed to TABLEA

This commit is contained in:
lukaseder 2017-04-20 18:11:43 +02:00
parent ebd9bac543
commit 7fe7d55889

View File

@ -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<W extends GeneratorWriter<W>> {
// [#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();
}
}
}