Browse Source

fix the filename case junk again without relying on OS-level tests; reverting earlier changes

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@552350 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 18 years ago
parent
commit
c0649769e0
2 changed files with 25 additions and 29 deletions
  1. +11
    -4
      src/main/org/apache/tools/ant/taskdefs/Move.java
  2. +14
    -25
      src/main/org/apache/tools/ant/util/FileUtils.java

+ 11
- 4
src/main/org/apache/tools/ant/taskdefs/Move.java View File

@@ -329,13 +329,20 @@ public class Move extends Copy {
|| getFilterChains().size() > 0) {
return false;
}
// ensure that parent dir of dest file exists!
// identical logic lives in FileUtils.rename():
File parent = destFile.getParentFile();
if (parent != null && !parent.exists()) {
parent.mkdirs();
} else if (destFile.isFile() && !getFileUtils().fileNameEquals(sourceFile, destFile)
&& !destFile.delete()) {
throw new BuildException("Unable to remove existing file " + destFile);
} else if (destFile.isFile()) {
sourceFile = getFileUtils().normalize(sourceFile.getAbsolutePath()).getCanonicalFile();
destFile = getFileUtils().normalize(destFile.getAbsolutePath());
if (destFile.equals(sourceFile)) {
//no point in renaming a file to its own canonical version...
return true;
}
if (!(sourceFile.equals(destFile.getCanonicalFile()) || destFile.delete())) {
throw new BuildException("Unable to remove existing file " + destFile);
}
}
return sourceFile.renameTo(destFile);
}


+ 14
- 25
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -65,9 +65,6 @@ public class FileUtils {
private static final boolean onDos = Os.isFamily("dos");
private static final boolean onWin9x = Os.isFamily("win9x");
private static final boolean onWindows = Os.isFamily("windows");
private static final boolean onMac = Os.isFamily("mac");

private static boolean caseSensitiveFileSystem;

static final int BUF_SIZE = 8192;

@@ -89,24 +86,6 @@ public class FileUtils {
*/
public static final long NTFS_FILE_TIMESTAMP_GRANULARITY = 1;

static {
try {
File tmpdir = new File(System.getProperty("java.io.tmpdir"));
final String filename = "ant-casesensitivity.tst";
new File(tmpdir, filename).createNewFile();
new File(tmpdir, filename.toUpperCase()).createNewFile();
String[] files = tmpdir.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return filename.equalsIgnoreCase(name);
}
});
caseSensitiveFileSystem = files.length == 2;
} catch (IOException e) {
//default as well as possible:
caseSensitiveFileSystem = !onWin9x && !onWindows && !onDos && !onMac;
}
}

/**
* A one item cache for fromUri.
* fromUri is called for each element when parseing ant build
@@ -1152,9 +1131,8 @@ public class FileUtils {
* @since Ant 1.5.3
*/
public boolean fileNameEquals(File f1, File f2) {
String name1 = normalize(f1.getAbsolutePath()).getAbsolutePath();
String name2 = normalize(f2.getAbsolutePath()).getAbsolutePath();
return caseSensitiveFileSystem ? name1.equals(name2) : name1.equalsIgnoreCase(name2);
return normalize(f1.getAbsolutePath()).getAbsolutePath().equals(
normalize(f2.getAbsolutePath()).getAbsolutePath());
}

/**
@@ -1175,7 +1153,17 @@ public class FileUtils {
* @since Ant 1.6
*/
public void rename(File from, File to) throws IOException {
if (to.exists() && !to.delete()) {
from = normalize(from.getAbsolutePath()).getCanonicalFile();
to = normalize(to.getAbsolutePath());
if (!from.exists()) {
System.err.println("Cannot rename nonexistent file " + from);
return;
}
if (from.equals(to)) {
System.err.println("Rename of " + from + " to " + to + " is a no-op.");
return;
}
if (to.exists() && !(from.equals(to.getCanonicalFile()) || to.delete())) {
throw new IOException("Failed to delete " + to + " while trying to rename " + from);
}
File parent = to.getParentFile();
@@ -1231,6 +1219,7 @@ public class FileUtils {
* @since Ant 1.7.1
*/
public boolean hasErrorInCase(File localFile) {
localFile = normalize(localFile.getAbsolutePath());
if (!localFile.exists()) {
return false;
}


Loading…
Cancel
Save