# Errors when freezing rails

Folks,

I am trying to freeze rails but am running into some errors that I
don't understand. I have tried couple ways based on results I got from
searching on the web as below. I thought freezing rails would be a
simple and quick thing but am stuck here. Any thoughts on what I may
be doing wrong?

Thanks,
-S

------------------------------------- First Way

I am hoping someone will have some thoughts on this issue. I even
tried creating a completely fresh rails app and then running rake
rails:freeze:gems right after the app creation and I get the same
error

I ran the command with --trace and I get the output as below. I looked
at the code in fileutils.rb (where trace points to) and found that it
tries to do a simple rename of activesupport-2.2.2 to activesupport
(as also indicated in the output). I don't understand why it does that
renaming but when I run the same command "rename activesupport-2.2.2
activesupport" on my command line it runs fine without giving the
"permission denied error" I am seeing in the output.

Any thoughts or pointers on what the issue maybe or how I can debug
further? Has anyone else seen this problem?

-S

** Invoke rails:freeze:gems (first_time)
** Execute rails:freeze:gems
Freezing to the gems for Rails 2.2.2
rm -rf vendor/rails
mkdir -p vendor/rails
cd vendor/rails
mv activesupport-2.2.2 activesupport
rm -rf vendor/rails
rake aborted!
Permission denied - activesupport-2.2.2 or activesupport
c:/ruby/lib/ruby/1.8/fileutils.rb:501:in rename'
c:/ruby/lib/ruby/1.8/fileutils.rb:501:in mv'
c:/ruby/lib/ruby/1.8/fileutils.rb:1379:in fu_each_src_dest'
c:/ruby/lib/ruby/1.8/fileutils.rb:1395:in fu_each_src_dest0'
c:/ruby/lib/ruby/1.8/fileutils.rb:1377:in fu_each_src_dest'
c:/ruby/lib/ruby/1.8/fileutils.rb:490:in mv'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1070:in mv'
26:in each'
c:/ruby/lib/ruby/1.8/fileutils.rb:121:in chdir'
c:/ruby/lib/ruby/1.8/fileutils.rb:121:in chdir'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1070:in chdir'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in call'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in execute'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in each'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in execute'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:578:in
invoke_with_call_chain'
c:/ruby/lib/ruby/1.8/monitor.rb:238:in synchronize'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:571:in
invoke_with_call_chain'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:564:in invoke'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2027:in
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in
top_level'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in each'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in
top_level'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in
standard_exception_handling'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1999:in
top_level'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1977:in run'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in
standard_exception_handling'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1974:in run'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/bin/rake:31
c:/ruby/bin/rake:19:in load'
c:/ruby/bin/rake:19

I've seen this before, in this thread:

Can you manually unpack activesupport (use 'gem unpack activesupport')
and then run 'perms \whatever\path\you\unpacked\it\to'?
There's something weird going on with the permissions on that
directory.

Also, are you running as an admin or with a limited user account? It
may make a difference, so try it as an admin if you aren't already.

--Matt Jones

Thanks Matt. I did see that thread as well after my post but that didn't
help me. I dug into the framework.rake file where the freeze:gems task
is located and added some debug statements there. I renamed the tasks to
be sure I am calling the right one (added 2_3_2 at the end - previously
I was trying to freeze 2.2.2 then started trying 2.3.2 in case there
one comment after the unpack statement completes and another one after
the mv statement completes. Below is the output of running the command.
The statement after unpack shows up but the one after mv doesn't.

Essentially code tells me that the unpacking is successful but when the
code tries to rename the file through "mv activesupport-2.3.2
activesupport" it fails with "permission denied". Here are some things
to note.

1. Running the freeze:gems task as below creates the vendor/rails and
then after unpacking it creates the activesupport-2.3.2 directory. That
directory contains *part* of the directory structure of the actual
activesupport-2.3.2 and with no files in any directory

2. I run the command "ren activesupport-2.3.2 activesupport" and it
works find - don't understand why that rename fails through the script
which gets called through fileutils.rb through the mv command (I will
have to dig into that next)

3. I cleaned out the vendor/rails directory and manually ran the "gem
unpack activesupport" and it created a *complete* copy of the
activesupport-2.3.2 directory structure *with the files*

4. Sounds like perms command is more for a linux box - doesn't seem to
be applicable for my XP box. The directory has read only permissions
when I check in the directory properties

5. I have admin privileges on my laptop - never had any issue with any
install so I don't understand what the "permission denied" error is
about. It almost sounds like the script is running under another user's
privileges but that doesn't sound right. Or is that possible?

I will continue to dig but I have already wasted so much time on
something that was supposed to be so trivial that it is hurting.

-S
** Invoke rails:freeze_2_3_2:gems_2_3_2 (first_time)
** Execute rails:freeze_2_3_2:gems_2_3_2
Statring gem freeze with deps =
actionpackactiverecordactionmaileractivesupportactiveresource from 2.3.2
Freezing to the gems for Rails 2.3.2
rm -rf vendor/rails
mkdir -p vendor/rails
cd vendor/rails
---> g.name = activesupport
--->Unpacked successfully - moving activesupport-2.3.2 to activesupport
mv activesupport-2.3.2 activesupport
rm -rf vendor/rails
rake aborted!
Permission denied - activesupport-2.3.2 or activesupport
c:/ruby/lib/ruby/1.8/fileutils.rb:501:in rename'
c:/ruby/lib/ruby/1.8/fileutils.rb:501:in mv'
c:/ruby/lib/ruby/1.8/fileutils.rb:1379:in fu_each_src_dest'
c:/ruby/lib/ruby/1.8/fileutils.rb:1395:in fu_each_src_dest0'
c:/ruby/lib/ruby/1.8/fileutils.rb:1377:in fu_each_src_dest'
c:/ruby/lib/ruby/1.8/fileutils.rb:490:in mv'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1070:in mv'
each'
c:/ruby/lib/ruby/1.8/fileutils.rb:121:in chdir'
c:/ruby/lib/ruby/1.8/fileutils.rb:121:in chdir'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1070:in chdir'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in call'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in execute'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in each'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in execute'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:578:in
invoke_with_call_chain'
c:/ruby/lib/ruby/1.8/monitor.rb:238:in synchronize'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:571:in
invoke_with_call_chain'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:564:in invoke'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2027:in
invoke_task'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in
top_level'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in each'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in
top_level'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in
standard_exception_handling'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1999:in
top_level'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1977:in run'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in
standard_exception_handling'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1974:in run'
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/bin/rake:31
c:/ruby/bin/rake:19

To add to it, I was able to run the mv command successfully through irb.
I will continue digging as to why the unpacking doesn't happen properly
and the mv fails when done through the rake rails:freeze:gems task.

If anyone has any thoughts/ideas - I look forward to it.

-S

irb(main):001:0> require 'fileutils.rb'
=> true
irb(main):003:0> include FileUtils
=> Object
irb(main):004:0> mv("activesupport-2.3.2", "activesupport")
=> 0
irb(main):005:0>

To eliminate any corruption I reinstalled ruby and rails (2.2.2) and
created an empty project but the same error persists with "rake
rails:freeze:gems".

"Permission denied - activesupport-2.2.2 or activesupport"

I added some debug code to the mv function in fileUtils but I can't get

1. How can I debug rake tasks? Is there a way to set breakpoints in
fileutils.rb when "rake rails:freeze:gems" runs so I can inspect the
data there?

2. How can I get information about what user is the command "rake
rails:freeze:gems" running under? I am system admin on my box so I just
don't understand the permission denied error I am seeing

I also tried to go down the other path I had tried earlier to freeze
rails with "rake rails:freeze:edge TAG=rel_2-2-2". It looks like there
the system can't find an unzip executable - I have Winzip on my box but
not sure if that matters. I saw in another post
(http://www.question-defense.com/2009/04/02/error-freezing-rails-usr-local-lib-ruby-1-8-fileutils-rb-1297-command-not-found-unzip-railszip/)
that doing a "yum install unzip" on a linux box apparently solved this
kind of problem. Is there an equivalent "unzip" install for XP box that
might address this aspect of the problem?

D:\TestRails2>rake rails:freeze:edge TAG=rel_2-2-2 --trace
(in D:/TestRails2)
** Invoke rails:freeze:edge (first_time)
** Execute rails:freeze:edge
cd vendor
http://dev.rubyonrails.org/archives/rails_edge.zip
Unpacking Rails
rm -rf rails
---> removed rails directory successfully
c:/ruby/bin/rake.bat: No such file or directory - unzip rails.zip
---> unzipped rails.zip
rm -f rails.zip
rm -f rails/Rakefile
rm -f rails/cleanlogs.sh
rm -f rails/pushgems.rb
rm -f rails/release.rb
touch rails/REVISION_7ce0778a1516110cf8015e59e2e8fac15032379c
rake aborted!
No such file or directory -
rails/REVISION_7ce0778a1516110cf8015e59e2e8fac15032379c

I don't really know what else to do to debug this problem. Could use
some help/pointers here.

Thanks,
-S

Found one other mention that might be of interest:

http://www.ruby-forum.com/topic/115921

This is with a similar problem related to renaming session files.

Given that the above issue doesn't share any code with the
rails:freeze:gems task, I'm guessing this is some kind of extremely
obscure Ruby bug. And given that it doesn't occur when the commands
are executed in irb, it seems likely that it's some kind of filesystem
race condition...

Sj, could you try dropping a sleep(10) call in between the unpack and
move steps? If that makes the problem go away, that will be useful
information...

--Matt Jones

Thanks Matt. I tried what you suggested and it seems to heave worked -
no idea why exactly though. Output included below. I played around with
sleep time and it seems like even 1 sec is enough to avoid the problem
with "permission denied" in renaming the directory. This clearly looks
like some RoR rbug with some race condition as you suspect. What is the
best way to report this to all those wonderful folks toiling away with
helping us with the RoR framework - especially given it is apparently so
hard to reproduce for anyone else?

I can go to sleep tonight with my mind at peace - at least for now!
Appreciate the suggestion/help Matt.

Freezing to the gems for Rails 2.2.2
rm -rf vendor/rails
mkdir -p vendor/rails
cd vendor/rails
--> Going to sleep for 1 seconds
--> Waking from sleep and about to start mv
mv activesupport-2.2.2 activesupport
--> Going to sleep for 1 seconds
--> Waking from sleep and about to start mv
mv activerecord-2.2.2 activerecord
--> Going to sleep for 1 seconds
--> Waking from sleep and about to start mv
mv actionpack-2.2.2 actionpack
--> Going to sleep for 1 seconds
--> Waking from sleep and about to start mv
mv actionmailer-2.2.2 actionmailer
--> Going to sleep for 1 seconds
--> Waking from sleep and about to start mv
mv activeresource-2.2.2 activeresource