Author: bodewig
Date: Fri Dec 19 05:39:16 2008
New Revision: 728019
URL: http://svn.apache.org/viewvc?rev=728019&view=rev
Log:
make diagnostics check the file it has just written in order to detect full
filesystems. PR 32676.
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/src/main/org/apache/tools/ant/Diagnostics.java
Modified: ant/core/trunk/WHATSNEW
URL:
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=728019&r1=728018&r2=728019&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Dec 19 05:39:16 2008
@@ -629,6 +629,11 @@
whether empty directories should be kept.
Bugzilla Report 43159.
+ * ant -diagnostics now checks that it can read as much from the
+ temporary directory as it has written. This may help detecting a
+ full filesystem.
+ Bugzilla Report 32676.
+
Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================
Modified: ant/core/trunk/src/main/org/apache/tools/ant/Diagnostics.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Diagnostics.java?rev=728019&r1=728018&r2=728019&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Diagnostics.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Diagnostics.java Fri Dec 19
05:39:16 2008
@@ -32,6 +32,7 @@
import java.io.PrintStream;
import java.io.InputStream;
import java.io.IOException;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Enumeration;
import java.util.Properties;
@@ -534,6 +535,7 @@
long now = System.currentTimeMillis();
File tempFile = null;
FileOutputStream fileout = null;
+ FileInputStream filein = null;
try {
tempFile = File.createTempFile("diag", "txt", tempDirectory);
//do some writing to it
@@ -544,10 +546,31 @@
}
fileout.close();
fileout = null;
+
+ // read to make sure the file has been written completely
+ Thread.sleep(1000);
+ filein = new FileInputStream(tempFile);
+ int total = 0;
+ int read = 0;
+ while ((read = filein.read(buffer, 0, KILOBYTE)) > 0) {
+ total += read;
+ }
+ filein.close();
+ filein = null;
+
long filetime = tempFile.lastModified();
- tempFile.delete();
- out.println("Temp dir is writeable");
long drift = filetime - now;
+ tempFile.delete();
+
+ out.print("Temp dir is writeable");
+ if (total != TEST_FILE_SIZE * KILOBYTE) {
+ out.println(", but seems to be full. Wrote "
+ + (TEST_FILE_SIZE * KILOBYTE)
+ + "but could only read " + total + " bytes.");
+ } else {
+ out.println();
+ }
+
out.println("Temp dir alignment with system clock is " + drift + "
ms");
if (Math.abs(drift) > BIG_DRIFT_LIMIT) {
out.println("Warning: big clock drift -maybe a network
filesystem");
@@ -556,8 +579,12 @@
ignoreThrowable(e);
out.println("Failed to create a temporary file in the temp dir " +
tempdir);
out.println("File " + tempFile + " could not be created/written
to");
+ } catch (InterruptedException e) {
+ ignoreThrowable(e);
+ out.println("Failed to check whether tempdir is writable");
} finally {
FileUtils.close(fileout);
+ FileUtils.close(filein);
if (tempFile != null && tempFile.exists()) {
tempFile.delete();
}