Skip to content

Commit

Permalink
make sure :mode parameter to upload() is honored
Browse files Browse the repository at this point in the history
  • Loading branch information
jamis committed May 29, 2008
1 parent c1e9279 commit 9be48bd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*unreleased*

* If :mode is given to upload() helper, do a chmod after to set the mode [Jamis Buck]

* Fix load_from_file method for windows users [Neil Wilson]

* Display a deprecation error if a remote git branch is specified [Tim Harper]
Expand Down
6 changes: 5 additions & 1 deletion lib/capistrano/configuration/actions/file_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module FileTransfer
# set the mode on the file.
def put(data, path, options={})
opts = options.dup
opts[:permissions] = opts.delete(:mode)
upload(StringIO.new(data), path, opts)
end

Expand All @@ -23,7 +22,12 @@ def get(remote_path, path, options={}, &block)
end

def upload(from, to, options={}, &block)
mode = options.delete(:mode)
transfer(:up, from, to, options, &block)
if mode
mode = mode.is_a?(Numeric) ? mode.to_s(8) : mode.to_s
run "chmod #{mode} #{to}"
end
end

def download(from, to, options={}, &block)
Expand Down
21 changes: 20 additions & 1 deletion test/configuration/actions/file_transfer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def setup

def test_put_should_delegate_to_upload
@config.expects(:upload).with { |from, to, opts|
from.string == "some data" && to == "test.txt" && opts == { :permissions => 0777 } }
from.string == "some data" && to == "test.txt" && opts == { :mode => 0777 } }
@config.expects(:run).never
@config.put("some data", "test.txt", :mode => 0777)
end

Expand All @@ -28,6 +29,24 @@ def test_upload_should_delegate_to_transfer
@config.upload("testl.txt", "testr.txt", :foo => "bar")
end

def test_upload_without_mode_should_not_try_to_chmod
@config.expects(:transfer).with(:up, "testl.txt", "testr.txt", :foo => "bar")
@config.expects(:run).never
@config.upload("testl.txt", "testr.txt", :foo => "bar")
end

def test_upload_with_mode_should_try_to_chmod
@config.expects(:transfer).with(:up, "testl.txt", "testr.txt", :foo => "bar")
@config.expects(:run).with("chmod 775 testr.txt")
@config.upload("testl.txt", "testr.txt", :mode => 0775, :foo => "bar")
end

def test_upload_with_symbolic_mode_should_try_to_chmod
@config.expects(:transfer).with(:up, "testl.txt", "testr.txt", :foo => "bar")
@config.expects(:run).with("chmod g+w testr.txt")
@config.upload("testl.txt", "testr.txt", :mode => "g+w", :foo => "bar")
end

def test_download_should_delegate_to_transfer
@config.expects(:transfer).with(:down, "testr.txt", "testl.txt", :foo => "bar")
@config.download("testr.txt", "testl.txt", :foo => "bar")
Expand Down

0 comments on commit 9be48bd

Please sign in to comment.