Tom Cloyd
3/7/2008 5:04:00 AM
Jano Svitok wrote:
> On Tue, Mar 4, 2008 at 1:15 PM, Tom Cloyd <tomcloyd@comcast.net> wrote:
>
>> Jano Svitok wrote:
>> > On Tue, Mar 4, 2008 at 11:58 AM, Tom Cloyd <tomcloyd@comcast.net> wrote:
>> >
>> >> I'm utterly baffled by this simple problem in a ruby program I've run a
>> >> number of time on Windows. I'm now running Kubuntu Linux, and things
>> >> work differently (!).
>> >>
>> >> This program reads a series of data CDs, cataloging their contents. To
>> >> stop the process, I input a zero length volume label (well, on Windows I
>> >> do, anyway; on Linux this errors off, but that's not my current problem).
>> >>
>> >> What I can't do is get the CD just read in to be released by the program
>> >> so I can read in the next one.
>> >>
>> >> Code:
>> >>
>> >> > archive_source_dir = '/cdrom' # this is where the CD appears when I
>> >> put it in the drive
>> >>
>> >> Processing begins when the program has the volume label of the CD (this
>> >> is used as the key in a hash containing an array of the tree paths).
>> >> When it has traversed the directory tree on the CD, it asks for the next
>> >> volume label. In Windows, I just punch the open button on the drive,
>> >> replaced the CD with a new one, close the drive, keyed in the new volume
>> >> label, and kept going. Linux won't release the CD.
>> >>
>> >> I've tried many things to get the CD to go release, including...
>> >> > archive_source_dir.close
>> >> > IO.close(archive_source_dir)
>> >> > File.close(archive_source_dir)
>> >>
>> >> I get "undefined method" errors on everything. I have no idea why. Isn't
>> >> everything a file in linux? Guess not.
>> >>
>> >> Plainly I'm missing some simple concept here, but I can't see it.
>> >>
>> >> Would appreciate any help.
>> >>
>> >> Tom
>> >>
>> >
>> > I guess this has something to do with mounting/umounting, though I
>> > don't know too much about automatic mounting in kubuntu.
>> > Try using `umount /cdrom` after you are done. (Don't forget to close
>> > any open files and move away from that dir).
>> > You might encounter some privileges problems ("only root can do") -
>> > try sudo in that case, or modify /etc/fstab to allow users to
>> > mount/umount.
>> >
>> > `eject` and `eject -t` might be useful as well.
>> >
>> >
>> >
>> The problem is that I need an unmount WHILE the program is running, and
>> it won't let go of the device. When I tried to close it, ruby refuses to
>> acknowledge knowing anything about "close". It appears that there is no
>> kernal#close, suddenly. Nothing works. I open the device and cannot shut
>> it down. If I try to do this through Linux, while my program is running,
>> I get "umount: /media/cdrom0: device is busy". It's a ruby problem - or
>> rather my problem in using ruby.
>>
>> So, again...having done this
>> >archive_source_dir = '/cdrom'
>> how do I "undo" it?
>>
>>
>> Any more ideas?
>>
>
> 1. lsof will show you your process' open files.
> 2. Make sure to use block form of File.open instead of File.new - it
> will close the file when you're done with it.
> 3. Instead of archive_source_dir.close() do Dir.chdir('/') or
> somewhere else. Or even better, use block form of Dir.chdir if you
> need to chdir into
> /cdrom
> 4. if you could post minimal program that makes trouble, maybe some
> more ideas will pop up. (e.g. strip as much as you can while it still
> causes the problem - I guess just traversing the CD will be enough)
>
>
>
Jano,
I'm slow getting back to this, but will in the next couple of hours.
Thank you for your promising ideas. I can see that they are likely to
get things moving on this problem, which I do need to solve. I'm
grateful for your help, and will get back to you with what I learn. I'm
thinking I'm close to a solution at this point.
Tom
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC
Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website & psychotherapy weblog)
<< sleightmind.wordpress.com >> (mental health issues weblog)
<< directpathdesign.com >> (web site design & consultation)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~