Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

support for preserving file/directory mode on copy #258

Merged
merged 1 commit into from

2 participants

@pmenglund

No description provided.

@sferik
Owner

Looks good.

@sferik sferik merged commit 8897e57 into erikhuda:master

1 check failed

Details default The Travis build failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 30, 2012
  1. @pmenglund
This page is out of date. Refresh to see the latest.
View
1  lib/thor/actions/directory.rb
@@ -38,6 +38,7 @@ module Actions
# destination<String>:: the relative path to the destination root.
# config<Hash>:: give :verbose => false to not log the status.
# If :recursive => false, does not look for paths recursively.
+ # If :mode => :preserve, preserve the file mode from the source.
#
# ==== Examples
#
View
8 lib/thor/actions/file_manipulation.rb
@@ -10,7 +10,9 @@ module Actions
# ==== Parameters
# source<String>:: the relative path to the source root.
# destination<String>:: the relative path to the destination root.
- # config<Hash>:: give :verbose => false to not log the status.
+ # config<Hash>:: give :verbose => false to not log the status, and
+ # :mode => :preserve, to preserve the file mode from the source.
+
#
# ==== Examples
#
@@ -28,6 +30,10 @@ def copy_file(source, *args, &block)
content = block.call(content) if block
content
end
+ if config[:mode] == :preserve
+ mode = File.stat(source).mode
+ chmod(destination, mode, config)
+ end
end
# Links the file from the relative source to the relative destination. If
View
7 spec/actions/directory_spec.rb
@@ -82,6 +82,13 @@ def exists_and_identical?(source_path, destination_path)
File.read(file).should == "FOO = FOO\n"
end
+ it "copies directories and preserved file mode" do
+ invoke! "preserve", "preserved", :mode => :preserve
+ original = File.join(source_root, "preserve", "script.sh")
+ copy = File.join(destination_root, "preserved", "script.sh")
+ File.stat(original).mode.should == File.stat(copy).mode
+ end
+
it "copies directories" do
invoke! "doc", "docs"
file = File.join(destination_root, "docs", "components")
View
7 spec/actions/file_manipulation_spec.rb
@@ -68,6 +68,13 @@ def file
exists_and_identical?("doc/README", "doc/README")
end
+ it "copies file from source to default destination and preserves file mode" do
+ action :copy_file, "preserve/script.sh", :mode => :preserve
+ original = File.join(source_root, "preserve/script.sh")
+ copy = File.join(destination_root, "preserve/script.sh")
+ File.stat(original).mode.should == File.stat(copy).mode
+ end
+
it "logs status" do
action(:copy_file, "task.thor").should == " create task.thor\n"
end
View
3  spec/fixtures/preserve/script.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exit 0
Something went wrong with that request. Please try again.