You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ni...@apache.org on 2010/09/29 21:30:10 UTC
svn commit: r1002819 - in /commons/proper/io/trunk/src:
java/org/apache/commons/io/FileSystemUtils.java
test/org/apache/commons/io/FileSystemUtilsTestCase.java
Author: niallp
Date: Wed Sep 29 19:30:10 2010
New Revision: 1002819
URL: http://svn.apache.org/viewvc?rev=1002819&view=rev
Log:
IO-209 FileSystemUtils freeSpaceKb fails to return correct size for a windows mount point - reported by Aditya Kishore
Modified:
commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java
commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java
Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java?rev=1002819&r1=1002818&r2=1002819&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java Wed Sep 29 19:30:10 2010
@@ -291,8 +291,8 @@ public class FileSystemUtils {
*/
long freeSpaceWindows(String path, long timeout) throws IOException {
path = FilenameUtils.normalize(path);
- if (path.length() > 2 && path.charAt(1) == ':') {
- path = path.substring(0, 2); // seems to make it work
+ if (path.length() > 0 && path.charAt(0) != '"') {
+ path = "\"" + path + "\"";
}
// build and run the 'dir' command
Modified: commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java?rev=1002819&r1=1002818&r2=1002819&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java (original)
+++ commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java Wed Sep 29 19:30:10 2010
@@ -203,7 +203,7 @@ public class FileSystemUtilsTestCase ext
"17/08/2005 21:44 <DIR> Desktop\n" +
" 7 File(s) 180260 bytes\n" +
" 10 Dir(s) 41411551232 bytes free";
- FileSystemUtils fsu = new MockFileSystemUtils(0, lines, "dir /-c C:");
+ FileSystemUtils fsu = new MockFileSystemUtils(0, lines, "dir /-c \"C:\"");
assertEquals(41411551232L, fsu.freeSpaceWindows("C:", -1));
}
@@ -220,10 +220,27 @@ public class FileSystemUtilsTestCase ext
"17/08/2005 21:44 <DIR> Desktop\n" +
" 7 File(s) 180260 bytes\n" +
" 10 Dir(s) 41411551232 bytes free";
- FileSystemUtils fsu = new MockFileSystemUtils(0, lines, "dir /-c C:");
+ FileSystemUtils fsu = new MockFileSystemUtils(0, lines, "dir /-c \"C:\\somedir\"");
assertEquals(41411551232L, fsu.freeSpaceWindows("C:\\somedir", -1));
}
+ public void testGetFreeSpaceWindows_String_quoted() throws Exception {
+ String lines =
+ " Volume in drive C is HDD\n" +
+ " Volume Serial Number is XXXX-YYYY\n" +
+ "\n" +
+ " Directory of C:\\Documents and Settings\\Xxxx\n" +
+ "\n" +
+ "19/08/2005 22:43 <DIR> .\n" +
+ "19/08/2005 22:43 <DIR> ..\n" +
+ "11/08/2005 01:07 81 build.properties\n" +
+ "17/08/2005 21:44 <DIR> Desktop\n" +
+ " 7 File(s) 180260 bytes\n" +
+ " 10 Dir(s) 41411551232 bytes free";
+ FileSystemUtils fsu = new MockFileSystemUtils(0, lines, "dir /-c \"C:\\somedir\"");
+ assertEquals(41411551232L, fsu.freeSpaceWindows("\"C:\\somedir\"", -1));
+ }
+
public void testGetFreeSpaceWindows_String_EmptyResponse() throws Exception {
String lines = "";
FileSystemUtils fsu = new MockFileSystemUtils(0, lines);