Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pretend leaves directories around when action contains empty_directory followed by an inside block #74

Closed
asanghi opened this issue Oct 6, 2010 · 1 comment

Comments

@asanghi
Copy link

asanghi commented Oct 6, 2010

Just investigating a rails bug (https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5716-rails-300-creates-directories-in-pretend-mode-minor-bug#ticket-5716-5).

The action in rails written as

def log
  empty_directory "log"

  inside "log" do
    %w( server production development test ).each do |file|
      create_file "#{file}.log"
      chmod "#{file}.log", 0666, :verbose => false
    end
  end
end

This leaves a log directory in the application even though the application is run with -p pretend mode.

Perhaps there is a bug in thor or the action needs to be written differently.

@asanghi
Copy link
Author

asanghi commented Oct 6, 2010

Pasting the conversation from the Rails ticket over here since we've ascertained that this is a thor bug.

def inside(dir='', config={}, &block)
  verbose = config.fetch(:verbose, false)

  say_status :inside, dir, verbose
  shell.padding += 1 if verbose
  @destination_stack.push File.expand_path(dir, destination_root)

  FileUtils.mkdir_p(destination_root) unless File.exist?(destination_root) # <--- what about pretend??
  FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield }

  @destination_stack.pop
  shell.padding -= 1 if verbose
end

--- from rails ticket ---
Ok good news is that it's definitely a Thor bug. Confirmed this with Jose. However he is too busy to work on this. Can you try and write the patch for Thor? The main thing to keep in mind is that in the pretend mode, the messages like —
create config/locales
create config/locales/en.yml
create config/boot.rb
create config/database.yml
Should still appear. So Jose has suggested that in pretend mode, you create the directory, pretend to create the files and then remove the directory.

-- end from rails ticket ---

I suppose the idea is to create the directory if it doesnt already exist and then remove it if it was indeed created by the thor action in the "inside" method.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant