From 6cc29239b3603a513225c5709d0fb6b73ebe2271 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 19 Dec 2008 13:39:16 +0000 Subject: [PATCH] make diagnostics check the file it has just written in order to detect full filesystems. PR 32676. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@728019 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 5 +++ .../org/apache/tools/ant/Diagnostics.java | 31 +++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 0f79bd3fb..cc70b0f7b 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -629,6 +629,11 @@ Other changes: 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 ============================================= diff --git a/src/main/org/apache/tools/ant/Diagnostics.java b/src/main/org/apache/tools/ant/Diagnostics.java index aa7ff3931..e172c7263 100644 --- a/src/main/org/apache/tools/ant/Diagnostics.java +++ b/src/main/org/apache/tools/ant/Diagnostics.java @@ -32,6 +32,7 @@ import java.io.FilenameFilter; 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 @@ public final class Diagnostics { 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 @@ public final class Diagnostics { } 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 @@ public final class Diagnostics { 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(); }