Skip to content

Commit

Permalink
Merge pull request #639 from hugocorbucci/master
Browse files Browse the repository at this point in the history
Fix #587
  • Loading branch information
rafaelfranca committed Nov 13, 2018
2 parents 1ec3eff + 371f2a3 commit 4344761
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/thor/actions/file_manipulation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def copy_file(source, *args, &block)
destination = args.first || source
source = File.expand_path(find_in_source_paths(source.to_s))

create_file destination, nil, config do
resulting_destination = create_file destination, nil, config do
content = File.binread(source)
content = yield(content) if block
content
end
if config[:mode] == :preserve
mode = File.stat(source).mode
chmod(destination, mode, config)
chmod(resulting_destination, mode, config)
end
end

Expand Down
8 changes: 8 additions & 0 deletions spec/actions/file_manipulation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ def file
expect(File.stat(original).mode).to eq(File.stat(copy).mode)
end

it "copies file from source to default destination and preserves file mode for templated filenames" do
expect(runner).to receive(:filename).and_return("app")
action :copy_file, "preserve/%filename%.sh", :mode => :preserve
original = File.join(source_root, "preserve/%filename%.sh")
copy = File.join(destination_root, "preserve/app.sh")
expect(File.stat(original).mode).to eq(File.stat(copy).mode)
end

it "logs status" do
expect(action(:copy_file, "command.thor")).to eq(" create command.thor\n")
end
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/preserve/%filename%.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

exit 0

0 comments on commit 4344761

Please sign in to comment.