doo 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,22 +6,28 @@ Doo::Base.class_eval do
6
6
 
7
7
  def replace(file, src, replace, opts = {})
8
8
  sep = SEPARATORS.detect { |x| !src.include?(x) && !replace.include?(x) }
9
- run "sed -i -e 's#{sep}#{src}#{sep}#{replace}#{sep}g' #{file}", opts
9
+ run "sed -i -e 's#{sep}#{src.escape_for_shell}#{sep}#{replace.escape_for_shell}#{sep}g' #{file}", opts
10
10
  end
11
11
 
12
12
  def append(file, text, opts = {})
13
- run "grep '#{text}' #{file} || echo '#{text}' >> #{file}", opts
13
+ run "grep '#{text.escape_for_shell}' #{file} || echo '#{text.escape_for_shell}' >> #{file}", opts
14
14
  end
15
15
 
16
16
  def sudo(cmd, opts = {})
17
17
  run(cmd, opts.merge(:sudo => true))
18
18
  end
19
19
 
20
- private
21
- def sudoize(cmd)
22
- "sudo sh -c \"#{cmd.gsub(/\"/, "\\\"")}\""
20
+ class String
21
+ def sudoize!
22
+ replace "sudo sh -c \"#{escape_for_shell}\""
23
+ end
24
+
25
+ def escape_for_shell
26
+ gsub "\"", "\\\""
27
+ end
23
28
  end
24
29
 
30
+ private
25
31
  def run!(cmd, opts = {})
26
32
  with_clone(opts) do
27
33
  if confirm
@@ -2,7 +2,7 @@ Doo::Base.class_eval do
2
2
  def run_locally(variables = {}, &block)
3
3
  with_clone(variables) do
4
4
  def run(cmd, opts = {})
5
- cmd = sudoize(cmd) if opts[:sudo]
5
+ cmd.sudoize! if opts[:sudo]
6
6
  run! cmd, opts
7
7
  end
8
8
 
@@ -6,8 +6,8 @@ Doo::Base.class_eval do
6
6
  cmdopts = ["-S \"~/.ssh/master-%l-%r@%h:%p\""]
7
7
  cmdopts << "-t" if !opts.include? :pty || opts[:pty]
8
8
  cmdopts << "-p#{ssh_port}" if defined? ssh_port
9
- remote_cmd = sudoize(remote_cmd) if opts[:sudo]
10
- run! "ssh #{cmdopts.join(' ')} #{user}@#{host} \"#{remote_cmd.gsub(/\"/, "\\\"")}\"", opts
9
+ remote_cmd.sudoize! if opts[:sudo]
10
+ run! "ssh #{cmdopts.join(' ')} #{user}@#{host} \"#{remote_cmd.escape_for_shell}\"", opts
11
11
  end
12
12
 
13
13
  def put(local, remote, opts = {})
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 0
10
- version: 0.6.0
9
+ - 1
10
+ version: 0.6.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mat Trudel
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-16 00:00:00 -05:00
18
+ date: 2010-12-17 00:00:00 -05:00
19
19
  default_executable: doo
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency