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

Fix "file clash" bug #541

Merged
merged 2 commits into from
Jul 6, 2017
Merged

Fix "file clash" bug #541

merged 2 commits into from
Jul 6, 2017

Conversation

nodo
Copy link

@nodo nodo commented Jan 25, 2017

Summary

In some cases creating a file would raise an exception, due to clashes with existing file. E.g. creating a file where a directory with the same name is present.

How to reproduce the bug

$ mkdir err
$ touch er/hello
$ irb
>> require 'thor'; class A < Thor; include Thor::Actions; end; a = A.new; a.create_file('./err/hello/boom')
      create  err/hello/boom
Errno::EEXIST: File exists @ dir_s_mkdir - /Users/anodari/other_projects/thor/err/hello
from /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/2.4.0/fileutils.rb:228:in `mkdir'

What happen using the bug fix

>> require './lib/thor'; class A < Thor; include Thor::Actions; end; a = A.new; a.create_file('./err/hello/boom')
  file_clash  err/hello/boom

I would be more than happy to discuss further this issue. Feel free to comment about the naming and the approach.

@nodo
Copy link
Author

nodo commented Jan 25, 2017

Regarding the travis checks:

WDYT?

@@ -112,11 +112,18 @@ def invoke_with_conflict_check(&block)
if exists?
on_conflict_behavior(&block)
else
say_status :create, :green
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this was changed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If say_status is before yield, in case of a conflict we have a misleading message. For instance:

create  doc/config/config.rb
file_clash  doc/config/config.rb

end

destination
rescue SystemCallError => e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to rescue the specific exception here and avoid the unless instead of the parent class.

@nodo
Copy link
Author

nodo commented Mar 3, 2017

Thanks for your review @rafaelfranca, sorry for the delay. I will address your comments in the next days.

@nodo nodo force-pushed the fix-file-clash branch 2 times, most recently from 42c887c to 36592e0 Compare March 18, 2017 19:53
In some cases creating a file would raise an exception, due to clashes
with existing file. E.g. creating a file where a directory with the same
name is present.

This fix rescue the exception and print a "file_clash" warning.
@nodo nodo force-pushed the fix-file-clash branch 2 times, most recently from 8758356 to ab0cdfe Compare March 18, 2017 20:06
@nodo
Copy link
Author

nodo commented Mar 18, 2017

@rafaelfranca Thanks again for your review. I have addressed you comments and rebase my branch.

@rafaelfranca rafaelfranca merged commit cb4a1d9 into rails:master Jul 6, 2017
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

Successfully merging this pull request may close these issues.

2 participants