Oddity with FileUtils.move

3 views
Skip to first unread message

nem...@gmail.com

unread,
Nov 19, 2009, 5:33:13 PM11/19/09
to 757.rb
I came across something weird today that burned a few hours to debug
even when I found what the problem area. See snippet of code below

It appears that when you use 'FileUtils', which replaces 'ftools' in
Ruby 1.9, to move a short file (18-lines, 759-characters) you have to
insert a wait – Argh! I hate to rely on timing in these situations,
but it is what I have at the moment. – otherwise you may be able to
open the file, and read it, but it might not contain anything and
@msg_text will be empty.

Thoughts?

-Michael

FileUtils.move(File.join(MAIL_INCOMING_PATH, ev.name), @mail_filename
= File.join(MAIL_BEING_PROCESSED_PATH, ev.name))

while (File.size?(@mail_filename) == nil) do
sleep 0.25
puts "loop"
end

@msg_text = IO.read(@mail_filename)

nem...@gmail.com

unread,
Nov 19, 2009, 5:34:41 PM11/19/09
to 757.rb
By the way this is happening on Fedora 11.

-Michael

On Nov 19, 5:33 pm, "757rb.groups.google....@nemonik.com"

Ken Collins

unread,
Nov 19, 2009, 6:27:55 PM11/19/09
to 75...@googlegroups.com

Not sure I follow, but check this out.
http://gist.github.com/239141

Even when I bump that up to say 30,000 lines, I still get the same result no matter if I comment out the sleep or not. Just tried it out with 300_000 too. Thoughts?

- Ken
> --
> You are subscribed to the 757.rb Google Groups
>
> To post to this group, send email to 75...@googlegroups.com
> Googl Group Page: http://groups.google.com/group/757rb
> Group Website: http://757rb.org/
> Group Meetup: http://ruby.meetup.com/130/

nem...@gmail.com

unread,
Nov 19, 2009, 8:12:48 PM11/19/09
to 75...@googlegroups.com

True you don't need the sleep, you can spin the loop printing "loop" until the loop condition evaluates false. My thought the move would be complete after the call to move the file not some ranfom time after.

There's a not more to the story, I'm catching the write of the source file on the tripping of create event using the inotify gem that in turn wraps Unix's inotify. So the file appears on a split second in the source before my script moves the file and seemingly isn't available til be read as I thought it would be. I guess this just the way of things.

- Michael

- Ken

Sent from my Verizon Wireless BlackBerry

Reply all
Reply to author
Forward
0 new messages