You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2006/03/13 23:27:11 UTC
svn commit: r385680 - in /jakarta/commons/proper/io/trunk/src:
java/org/apache/commons/io/FileSystemUtils.java
test/org/apache/commons/io/FileSystemUtilsTestCase.java
Author: scolebourne
Date: Mon Mar 13 14:27:09 2006
New Revision: 385680
URL: http://svn.apache.org/viewcvs?rev=385680&view=rev
Log:
Handle 512byte blocks such as on OS X
Modified:
jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java
jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java
Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java?rev=385680&r1=385679&r2=385680&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java (original)
+++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java Mon Mar 13 14:27:09 2006
@@ -100,8 +100,10 @@
* Returns the free space on a drive or volume by invoking
* the command line.
* This method does not normalize the result, and typically returns
- * bytes on Windows and Kilobytes on Unix.
- * See also {@link #freeSpaceKb(String)}.
+ * bytes on Windows, 512 byte units on OS X and kilobytes on Unix.
+ * <p>
+ * See also {@link #freeSpaceKb(String)} for a better implementation
+ * which normalizes to kilobytes.
* <p>
* Note that some OS's are NOT currently supported, including OS/390.
* <pre>
Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java?rev=385680&r1=385679&r2=385680&view=diff
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java (original)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java Mon Mar 13 14:27:09 2006
@@ -18,6 +18,7 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.io.StringReader;
import junit.framework.Test;
@@ -62,10 +63,28 @@
public void testGetFreeSpace_String() throws Exception {
// test coverage, as we can't check value
if (File.separatorChar == '/') {
- // test assumes Unix using 1kb blocks
+ // have to figure out unix block size
+ Process proc = Runtime.getRuntime().exec(new String[] {"df", "/"});
+ boolean kilobyteBlock = true;
+ BufferedReader r = null;
+ try {
+ r = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+ String line = r.readLine();
+ if (line.toLowerCase().indexOf("512") >= 0) {
+ kilobyteBlock = false;
+ }
+ } finally {
+ IOUtils.closeQuietly(r);
+ }
+
+ // now perform the test
long free = FileSystemUtils.freeSpace("/");
long kb = FileSystemUtils.freeSpaceKb("/");
- assertEquals((double) free, (double) kb, 256d);
+ if (kilobyteBlock) {
+ assertEquals((double) free, (double) kb, 256d);
+ } else {
+ assertEquals((double) free / 2d, (double) kb, 256d);
+ }
} else {
long bytes = FileSystemUtils.freeSpace("");
long kb = FileSystemUtils.freeSpaceKb("");
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org