Author: scolebourne Date: Tue Aug 29 13:54:47 2006 New Revision: 438209 URL: http://svn.apache.org/viewvc?rev=438209&view=rev Log: IO-91 - FileSystemUtils.freeSpace deprecated, replaced by freeSpaceKb Document freeSpace not working with SunOS 5 info from Magnus Grimsell
Modified: jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt 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/RELEASE-NOTES.txt URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt?rev=438209&r1=438208&r2=438209&view=diff ============================================================================== --- jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt (original) +++ jakarta/commons/proper/io/trunk/RELEASE-NOTES.txt Tue Aug 29 13:54:47 2006 @@ -29,6 +29,12 @@ - WildcardFilter deprecated, replaced by WildcardFileFilter - old class only accepted files, thus had a confusing dual purpose +- FileSystemUtils.freeSpace deprecated, replaced by freeSpaceKb + - freeSpace returns a result that varies by operating system and + thus isn't that useful + - freeSpaceKb returns much better and more consistent results + - freeSpaceKb existed in v1.2, so this is a gentle cutover + Bug fixes from 1.2 ------------------ @@ -41,6 +47,9 @@ - FileSystemUtils.freeSpace/freeSpaceKb [IO-90] - Avoid infinite looping in Windows - Catch more errors with nice messages + +- FileSystemUtils.freeSpace [IO-91] + - This is now documented not to work on SunOS 5 Enhancements from 1.2 Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java?rev=438209&r1=438208&r2=438209&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 Tue Aug 29 13:54:47 2006 @@ -110,11 +110,11 @@ * the command line. * This method does not normalize the result, and typically returns * bytes on Windows, 512 byte units on OS X and kilobytes on Unix. + * As this is not very useful, this method is deprecated in favour + * of [EMAIL PROTECTED] #freeSpaceKb(String)} which returns a result in kilobytes. * <p> - * See also [EMAIL PROTECTED] #freeSpaceKb(String)} for a better implementation - * which normalizes to kilobytes. - * <p> - * Note that some OS's are NOT currently supported, including OS/390. + * Note that some OS's are NOT currently supported, including OS/390 + * and SunOS 5. (SunOS is supported by <code>freeSpaceKb</code>.) * <pre> * FileSystemUtils.freeSpace("C:"); // Windows * FileSystemUtils.freeSpace("/volume"); // *nix @@ -127,6 +127,9 @@ * @throws IllegalArgumentException if the path is invalid * @throws IllegalStateException if an error occurred in initialisation * @throws IOException if an error occurs when finding the free space + * @since Commons IO 1.1, enhanced OS support in 1.2 and 1.3 + * @deprecated Use freeSpaceKb(String) + * Deprecated from 1.3, may be removed in 2.0 */ public static long freeSpace(String path) throws IOException { return INSTANCE.freeSpaceOS(path, OS, false); @@ -136,20 +139,26 @@ /** * Returns the free space on a drive or volume in kilobytes by invoking * the command line. - * Note that some OS's are NOT currently supported, including OS/390. * <pre> * FileSystemUtils.freeSpaceKb("C:"); // Windows * FileSystemUtils.freeSpaceKb("/volume"); // *nix * </pre> * The free space is calculated via the command line. * It uses 'dir /-c' on Windows, 'df -kP' on AIX/HP-UX and 'df -k' on other Unix. + * <p> + * In order to work, you must be running Windows, or have a implementation of + * Unix df that supports GNU format when passed -k (or -kP). If you are going + * to rely on this code, please check that it works on your OS by running + * some simple tests to compare the command line with the output from this class. + * If your operating system isn't supported, please raise a JIRA call detailing + * the exact result from df -k and as much other detail as possible, thanks. * * @param path the path to get free space for, not null, not empty on Unix * @return the amount of free drive space on the drive or volume in kilobytes * @throws IllegalArgumentException if the path is invalid * @throws IllegalStateException if an error occurred in initialisation * @throws IOException if an error occurs when finding the free space - * @since Commons IO 1.2 + * @since Commons IO 1.2, enhanced OS support in 1.3 */ public static long freeSpaceKb(String path) throws IOException { return INSTANCE.freeSpaceOS(path, OS, true); Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileSystemUtilsTestCase.java?rev=438209&r1=438208&r2=438209&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 Tue Aug 29 13:54:47 2006 @@ -296,20 +296,53 @@ } - public void testGetFreeSpaceUnix_String_NormalResponse() throws Exception { + public void testGetFreeSpaceUnix_String_NormalResponseLinux() throws Exception { + // from Sourceforge 'GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu)' String lines = "Filesystem 1K-blocks Used Available Use% Mounted on\n" + - "xxx:/home/users/s 14428928 12956424 1472504 90% /home/users/s"; + "/dev/xxx 497944 308528 189416 62% /"; FileSystemUtils fsu = new MockFileSystemUtils(0, lines); - assertEquals(1472504L, fsu.freeSpaceUnix("/home/users/s", false, false)); + assertEquals(189416L, fsu.freeSpaceUnix("/", false, false)); } - public void testGetFreeSpaceUnix_String_NormalResponseKb() throws Exception { + public void testGetFreeSpaceUnix_String_NormalResponseFreeBSD() throws Exception { + // from Apache 'FreeBSD 6.1-RELEASE (SMP-turbo)' + String lines = + "Filesystem 1K-blocks Used Avail Capacity Mounted on\n" + + "/dev/xxxxxx 128990 102902 15770 87% /"; + FileSystemUtils fsu = new MockFileSystemUtils(0, lines); + assertEquals(15770L, fsu.freeSpaceUnix("/", false, false)); + } + + //----------------------------------------------------------------------- + public void testGetFreeSpaceUnix_String_NormalResponseKbLinux() throws Exception { + // from Sourceforge 'GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu)' + // df, df -k and df -kP are all identical String lines = "Filesystem 1K-blocks Used Available Use% Mounted on\n" + - "xxx:/home/users/s 14428928 12956424 1472504 90% /home/users/s"; + "/dev/xxx 497944 308528 189416 62% /"; + FileSystemUtils fsu = new MockFileSystemUtils(0, lines); + assertEquals(189416L, fsu.freeSpaceUnix("/", true, false)); + } + + public void testGetFreeSpaceUnix_String_NormalResponseKbFreeBSD() throws Exception { + // from Apache 'FreeBSD 6.1-RELEASE (SMP-turbo)' + // df and df -k are identical, but df -kP uses 512 blocks (not relevant as not used) + String lines = + "Filesystem 1K-blocks Used Avail Capacity Mounted on\n" + + "/dev/xxxxxx 128990 102902 15770 87% /"; + FileSystemUtils fsu = new MockFileSystemUtils(0, lines); + assertEquals(15770L, fsu.freeSpaceUnix("/", true, false)); + } + + public void testGetFreeSpaceUnix_String_NormalResponseKbSolaris() throws Exception { + // from IO-91 - ' SunOS et 5.10 Generic_118822-25 sun4u sparc SUNW,Ultra-4' + // non-kb response does not contain free space - see IO-91 + String lines = + "Filesystem kbytes used avail capacity Mounted on\n" + + "/dev/dsk/x0x0x0x0 1350955 815754 481163 63%"; FileSystemUtils fsu = new MockFileSystemUtils(0, lines); - assertEquals(1472504L, fsu.freeSpaceUnix("/home/users/s", true, false)); + assertEquals(481163L, fsu.freeSpaceUnix("/dev/dsk/x0x0x0x0", true, false)); } public void testGetFreeSpaceUnix_String_LongResponse() throws Exception { --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]