lib/vendor/thor/lib/thor/actions/file_manipulation.rb in engineyard-2.1.1 vs lib/vendor/thor/lib/thor/actions/file_manipulation.rb in engineyard-2.1.2

- old
+ new

@@ -8,11 +8,13 @@ # the destination is not given it's assumed to be equal to the source. # # ==== 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 # # copy_file "README", "doc/README" # @@ -26,10 +28,14 @@ create_file destination, nil, config do content = File.binread(source) 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 # the destination is not given it's assumed to be equal to the source. # @@ -121,11 +127,11 @@ # path<String>:: the name of the file to change mode # config<Hash>:: give :verbose => false to not log the status. # # ==== Example # - # chmod "script/*", 0755 + # chmod "script/server", 0755 # def chmod(path, mode, config={}) return unless behavior == :invoke path = File.expand_path(path, destination_root) say_status :chmod, relative_to_original_destination_root(path), config.fetch(:verbose, true) @@ -243,10 +249,10 @@ # uncomment_lines 'config/initializers/session_store.rb', /active_record/ # def uncomment_lines(path, flag, *args) flag = flag.respond_to?(:source) ? flag.source : flag - gsub_file(path, /^(\s*)#\s*(.*#{flag})/, '\1\2', *args) + gsub_file(path, /^(\s*)#[[:blank:]]*(.*#{flag})/, '\1\2', *args) end # Comment all lines matching a given regex. It will leave the space # which existed before the beginning of the line in tact and will insert # a single space after the comment hash.