Author: mbenson
Date: Sun Jul 1 12:01:07 2007
New Revision: 552350
URL: http://svn.apache.org/viewvc?view=rev&rev=552350
Log:
fix the filename case junk again without relying on OS-level tests; reverting
earlier changes
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Move.java
ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Move.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Move.java?view=diff&rev=552350&r1=552349&r2=552350
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Move.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Move.java Sun Jul 1
12:01:07 2007
@@ -329,13 +329,20 @@
|| 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);
}
Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java?view=diff&rev=552350&r1=552349&r2=552350
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java Sun Jul 1
12:01:07 2007
@@ -65,9 +65,6 @@
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 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 @@
* @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 @@
* @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 @@
* @since Ant 1.7.1
*/
public boolean hasErrorInCase(File localFile) {
+ localFile = normalize(localFile.getAbsolutePath());
if (!localFile.exists()) {
return false;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]