Forum: JRuby Cross-platform way to list all drives/volumes/mount-points?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0c1520038e7f70997042b0c9e721df76?d=identicon&s=25 James Britt (Guest)
on 2009-06-06 02:38
(Received via mailing list)
Hey all,

I'm looking for a way to reliably list all drive letters or volume names
  or mount points on a system.

Google has not helped me.  Best I could find was
java.io.File.listRoots(), but on my Linux box it simply gives '/' as the
sole root name, despite other devices being mounted.

Ultimately I want to check free disk space.  The Apache project's
org.apache.commons.io.FileSystemUtils  has freeSpaceKb, but it needs to
be told the path to check.

Is there some Java/JRuby/Ruby way to do this across Win32, *nix, and
OSX?  Pretty please? :)

Worst case, I fall back to platform detection and some use of regexen
and shell commands.  But I thought perhaps someone has blazed this path
already.

Thanks,


James


--

Neurogami - Smart application development

http://www.neurogami.com

james@neurogami.com





---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Ede2aa10c6462f1d825143879be59e38?d=identicon&s=25 Charles Oliver Nutter (Guest)
on 2009-06-07 20:13
(Received via mailing list)
James Britt wrote:
> org.apache.commons.io.FileSystemUtils  has freeSpaceKb, but it needs to
> be told the path to check.
>
> Is there some Java/JRuby/Ruby way to do this across Win32, *nix, and
> OSX?  Pretty please? :)
>
> Worst case, I fall back to platform detection and some use of regexen
> and shell commands.  But I thought perhaps someone has blazed this path
> already.

That's the only thing that comes to mind...searching fstab or running
"mount" and so on. Maybe ask on ruby-talk and see if someone there has
an idea?

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
0c1520038e7f70997042b0c9e721df76?d=identicon&s=25 James Britt (Guest)
on 2009-06-07 23:15
(Received via mailing list)
Charles Oliver Nutter wrote:
> James Britt wrote:

>>
>> Worst case, I fall back to platform detection and some use of regexen
>> and shell commands.  But I thought perhaps someone has blazed this
>> path already.
>
> That's the only thing that comes to mind...searching fstab or running
> "mount" and so on. Maybe ask on ruby-talk and see if someone there has
> an idea?


I may do that.  Best I saw was a sysutils gem, but it uses native code.

So far, I've written some methods that grab the results of `df` and grab
  the names of things mounted off /dev/*



Seems OK, if you don't stare directly at it.

James

--

Neurogami - Smart application development

http://www.neurogami.com

james@neurogami.com





---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Ede2aa10c6462f1d825143879be59e38?d=identicon&s=25 Charles Oliver Nutter (Guest)
on 2009-06-09 21:08
(Received via mailing list)
Trejkaz wrote:
>
> I wonder if NIO2 is going to give us this API.  It would be nice.

Probably a good chance. I wonder how much of it is in the dev builds of
Java 7?

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
0c1520038e7f70997042b0c9e721df76?d=identicon&s=25 James Britt (Guest)
on 2009-06-10 00:30
(Received via mailing list)
Charles Oliver Nutter wrote:
>>
>> That doesn't sound very cross-platform.  What about our poor friends
>> saddled with that W-word OS? :-)
>>
>> I wonder if NIO2 is going to give us this API.  It would be nice.
>
> Probably a good chance. I wonder how much of it is in the dev builds of
> Java 7?


Here's what I ended up doing:

Check the CONFIG['target_os'].  If not mswin32, call df and parse the
text.

Else, call

      java.io.File.list_roots.map{ |r| r.path }

I then used

    org.apache.commons.io.FileSystemUtils.freeSpace path

to get the free space (which, as it seems, shells out to assorted
platform-specific commands, such as 'df'. :) )


James

--

Neurogami - Smart application development

http://www.neurogami.com

james@neurogami.com





---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2009-06-10 01:43
(Received via mailing list)
On Tue, Jun 9, 2009 at 5:30 PM, James Britt<james@neurogami.com> wrote:
>   org.apache.commons.io.FileSystemUtils.freeSpace path
>
> to get the free space (which, as it seems, shells out to assorted
> platform-specific commands, such as 'df'. :) )

Sounds like a good gem :)

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
0c1520038e7f70997042b0c9e721df76?d=identicon&s=25 James Britt (Guest)
on 2009-06-10 03:37
(Received via mailing list)
Charles Oliver Nutter wrote:

> Sounds like a good gem :)


What?  really-hacky-free-space-0.0.1.gem?


It feels really fragile.


Maybe a gist would work better. :)

James

--

Neurogami - Smart application development

http://www.neurogami.com

james@neurogami.com





---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
This topic is locked and can not be replied to.