You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Paulo Gaspar <de...@kebom.net> on 2005/05/05 13:44:01 UTC

FileSystemUtils is probably buggy...

Hi Frank,


Having a look at
http://svn.apache.org/viewcvs.cgi/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java?view=markup

I find the following issues:
  - FileSystemUtils.getFreeSpaceWindows() will only work on English 
Windows versions
     because of the dependency on finding the "bytes free" string in
       int bfl = line.indexOf("bytes free");
    You can probably cover a larger set of international versions 
(although probably not all)
    just by keeping the last line with text and find its last continuous 
segment of digits.

  - Then , the Unix version starts like this:
    private static long getFreeSpaceUnix(String path) throws IOException {
        // build and run the 'dir' command
        String[] cmdAttrbs = new String[3];
        cmdAttrbs[0] = "cmd.exe";
        cmdAttrbs[1] = "/C";
        cmdAttrbs[2] = "df " + path;

    I am no big Unix expert, but you rely on an "cmd.exe" on Unix?????
    (A friend of mine that uses Linux quite often expressed some doubts 
about this too!)

    I thought that on Unix "df" is an executable you can directly call!
    Since I am no Unix expert, could you please enlighten me.


Anyway, the code looks like a stab on the right direction.


Regards,
Paulo Gaspar


Frank W. Zammetti wrote:

 > Ah, that would explain much :)  Thank you Niall!
 >
 > (P.S., I was only asking about this because someone else sent me a 
private eMail asking where it was... they remembered seeing discussion 
of it some time ago and thought it would be perfect for their needs... 
otherwise I wouldn't have noticed)
 >
 > Frank
 >
 > Niall Pemberton wrote:
 >
 >> Frank,
 >>
 >> The whole of commons has moved from CVS to SVN - your 
FileSystemUtils class
 >> is in SVN:
 >>
 >> http://svn.apache.org/viewcvs.cgi/jakarta/commons/proper/io/trunk/
 >>
 >> Niall
 >>
 >> ----- Original Message ----- From: "Frank W. Zammetti" 
<fz...@omnytex.com>
 >> Sent: Thursday, May 05, 2005 4:19 AM
 >>
 >>
 >>
 >>> It looks like the FileSystemUtils class I wrote that contained the
 >>> method to get free space on a volume in a cross-platform manner has 
been
 >>> removed... Or am I just missing it?  It the later, please point me 
at it
 >>> because I'm not seeing it in CVS... If the former though, who 
removed it
 >>> and why?
 >>
 >>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: FileSystemUtils is probably buggy...

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Good call on point 1... that never even occurred to me but your 
absolutely right.  That's typical "America is the only country in the 
world" thinking I suppose :)

The second point I actually have to look at the code some more and 
remember what I was thinking because I can't imagine ever thinking it 
would be right to use cmd.exe on *nix... I'm no big Unix expert either, 
far from it, but I can't imagine why I ever thought cmd.exe should be 
used (I'm actually guessing that is a cut-and-paste error that just 
happened to work in my Linux test environments and so I never noticed).

I'll tackle those first chance I get, thanks for looking!

Frank

Paulo Gaspar wrote:
> Hi Frank,
> 
> 
> Having a look at
> http://svn.apache.org/viewcvs.cgi/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileSystemUtils.java?view=markup 
> 
> 
> I find the following issues:
>  - FileSystemUtils.getFreeSpaceWindows() will only work on English 
> Windows versions
>     because of the dependency on finding the "bytes free" string in
>       int bfl = line.indexOf("bytes free");
>    You can probably cover a larger set of international versions 
> (although probably not all)
>    just by keeping the last line with text and find its last continuous 
> segment of digits.
> 
>  - Then , the Unix version starts like this:
>    private static long getFreeSpaceUnix(String path) throws IOException {
>        // build and run the 'dir' command
>        String[] cmdAttrbs = new String[3];
>        cmdAttrbs[0] = "cmd.exe";
>        cmdAttrbs[1] = "/C";
>        cmdAttrbs[2] = "df " + path;
> 
>    I am no big Unix expert, but you rely on an "cmd.exe" on Unix?????
>    (A friend of mine that uses Linux quite often expressed some doubts 
> about this too!)
> 
>    I thought that on Unix "df" is an executable you can directly call!
>    Since I am no Unix expert, could you please enlighten me.
> 
> 
> Anyway, the code looks like a stab on the right direction.
> 
> 
> Regards,
> Paulo Gaspar
> 
> 
> Frank W. Zammetti wrote:
> 
>  > Ah, that would explain much :)  Thank you Niall!
>  >
>  > (P.S., I was only asking about this because someone else sent me a 
> private eMail asking where it was... they remembered seeing discussion 
> of it some time ago and thought it would be perfect for their needs... 
> otherwise I wouldn't have noticed)
>  >
>  > Frank
>  >
>  > Niall Pemberton wrote:
>  >
>  >> Frank,
>  >>
>  >> The whole of commons has moved from CVS to SVN - your 
> FileSystemUtils class
>  >> is in SVN:
>  >>
>  >> http://svn.apache.org/viewcvs.cgi/jakarta/commons/proper/io/trunk/
>  >>
>  >> Niall
>  >>
>  >> ----- Original Message ----- From: "Frank W. Zammetti" 
> <fz...@omnytex.com>
>  >> Sent: Thursday, May 05, 2005 4:19 AM
>  >>
>  >>
>  >>
>  >>> It looks like the FileSystemUtils class I wrote that contained the
>  >>> method to get free space on a volume in a cross-platform manner has 
> been
>  >>> removed... Or am I just missing it?  It the later, please point me 
> at it
>  >>> because I'm not seeing it in CVS... If the former though, who 
> removed it
>  >>> and why?
>  >>
>  >>
> 
> 
> 
> 
> 
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org