@@ -64,6 +64,10 @@ public class FileSystemUtils {
6464
6565 /** The operating system flag. */
6666 private static final int OS ;
67+
68+ /** The path to df */
69+ private static String dfPath = "df" ;
70+
6771 static {
6872 int os = OTHER ;
6973 try {
@@ -76,16 +80,18 @@ public class FileSystemUtils {
7680 if (osName .indexOf ("windows" ) != -1 ) {
7781 os = WINDOWS ;
7882 } else if (osName .indexOf ("linux" ) != -1 ||
79- osName .indexOf ("sun os" ) != -1 ||
80- osName .indexOf ("sunos" ) != -1 ||
81- osName .indexOf ("solaris" ) != -1 ||
8283 osName .indexOf ("mpe/ix" ) != -1 ||
8384 osName .indexOf ("freebsd" ) != -1 ||
8485 osName .indexOf ("irix" ) != -1 ||
8586 osName .indexOf ("digital unix" ) != -1 ||
8687 osName .indexOf ("unix" ) != -1 ||
8788 osName .indexOf ("mac os x" ) != -1 ) {
8889 os = UNIX ;
90+ } else if (osName .indexOf ("sun os" ) != -1 ||
91+ osName .indexOf ("sunos" ) != -1 ||
92+ osName .indexOf ("solaris" ) != -1 ) {
93+ os = POSIX_UNIX ;
94+ dfPath = "/usr/xpg4/bin/df" ;
8995 } else if (osName .indexOf ("hp-ux" ) != -1 ||
9096 osName .indexOf ("aix" ) != -1 ) {
9197 os = POSIX_UNIX ;
@@ -116,7 +122,7 @@ public FileSystemUtils() {
116122 * of {@link #freeSpaceKb(String)} which returns a result in kilobytes.
117123 * <p>
118124 * Note that some OS's are NOT currently supported, including OS/390,
119- * OpenVMS and and SunOS 5. (SunOS is supported by <code>freeSpaceKb</code>.)
125+ * OpenVMS.
120126 * <pre>
121127 * FileSystemUtils.freeSpace("C:"); // Windows
122128 * FileSystemUtils.freeSpace("/volume"); // *nix
@@ -317,14 +323,14 @@ long freeSpaceUnix(String path, boolean kb, boolean posix) throws IOException {
317323 flags += "P" ;
318324 }
319325 String [] cmdAttribs =
320- (flags .length () > 1 ? new String [] {"df" , flags , path } : new String [] {"df" , path });
326+ (flags .length () > 1 ? new String [] {dfPath , flags , path } : new String [] {dfPath , path });
321327
322328 // perform the command, asking for up to 3 lines (header, interesting, overflow)
323329 List <String > lines = performCommand (cmdAttribs , 3 );
324330 if (lines .size () < 2 ) {
325331 // unknown problem, throw exception
326332 throw new IOException (
327- "Command line 'df ' did not return info as expected " +
333+ "Command line '" + dfPath + " ' did not return info as expected " +
328334 "for path '" + path + "'- response was " + lines );
329335 }
330336 String line2 = lines .get (1 ); // the line we're interested in
@@ -338,7 +344,7 @@ long freeSpaceUnix(String path, boolean kb, boolean posix) throws IOException {
338344 tok = new StringTokenizer (line3 , " " );
339345 } else {
340346 throw new IOException (
341- "Command line 'df ' did not return data as expected " +
347+ "Command line '" + dfPath + " ' did not return data as expected " +
342348 "for path '" + path + "'- check path is valid" );
343349 }
344350 } else {
@@ -364,14 +370,14 @@ long parseBytes(String freeSpace, String path) throws IOException {
364370 long bytes = Long .parseLong (freeSpace );
365371 if (bytes < 0 ) {
366372 throw new IOException (
367- "Command line 'df ' did not find free space in response " +
373+ "Command line '" + dfPath + " ' did not find free space in response " +
368374 "for path '" + path + "'- check path is valid" );
369375 }
370376 return bytes ;
371377
372378 } catch (NumberFormatException ex ) {
373379 throw new IOException (
374- "Command line 'df ' did not return numeric data as expected " +
380+ "Command line '" + dfPath + " ' did not return numeric data as expected " +
375381 "for path '" + path + "'- check path is valid" );
376382 }
377383 }
0 commit comments