Permalink
Browse files

support for preserving file/directory mode on copy

  • Loading branch information...
1 parent 593722c commit 84c90506405d252d57599a3f87b6371ff72ebe6a @pmenglund pmenglund committed Sep 30, 2012
@@ -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
#
@@ -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
@@ -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")
@@ -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
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exit 0

0 comments on commit 84c9050

Please sign in to comment.