Permalink
Browse files

• Quote paths in shellouts (popen and backticks) on local connections.

• Add tests to verify that read_archive and write_archive work for paths with spaces.
  The other changed method is `#size`, which doesn’t work portably.
  • Loading branch information...
1 parent 0c34b72 commit 80af992cbd2b8460ba4c1b127d8cb3b1eb8e1a04 @mkhl mkhl committed with Jan 25, 2009
Showing with 16 additions and 3 deletions.
  1. +3 −3 lib/rush/local.rb
  2. +13 −0 spec/local_spec.rb
View
@@ -83,12 +83,12 @@ def copy(src, dst)
# transmitted to another server for a copy or move. Note that archive
# operations have the dir name implicit in the archive.
def read_archive(full_path)
- `cd #{::File.dirname(full_path)}; tar c #{::File.basename(full_path)}`
+ `cd #{Rush.quote(::File.dirname(full_path))}; tar c #{Rush.quote(::File.basename(full_path))}`
end
# Extract an in-memory archive to a dir.
def write_archive(archive, dir)
- IO.popen("cd #{dir}; tar x", "w") do |p|
+ IO.popen("cd #{Rush::quote(dir)}; tar x", "w") do |p|
p.write archive
end
end
@@ -135,7 +135,7 @@ def set_access(full_path, access)
# Fetch the size of a dir, since a standard file stat does not include the
# size of the contents.
def size(full_path)
- `du -sb #{full_path}`.match(/(\d+)/)[1].to_i
+ `du -sb #{Rush.quote(full_path)}`.match(/(\d+)/)[1].to_i
end
# Get the list of processes as an array of hashes.
View
@@ -194,6 +194,11 @@
@con.read_archive(@sandbox_dir).size.should > 50
end
+ it "read_archive works for paths with spaces" do
+ system "mkdir -p #{@sandbox_dir}/with\\ space; touch #{@sandbox_dir}/with\\ space/a"
+ @con.read_archive("#{@sandbox_dir}/with space").size.should > 50
+ end
+
it "write_archive to turn a byte stream into a dir" do
system "cd #{@sandbox_dir}; mkdir -p a; touch a/b; tar cf xfer.tar a; mkdir dst"
archive = File.read("#{@sandbox_dir}/xfer.tar")
@@ -202,6 +207,14 @@
File.exists?("#{@sandbox_dir}/dst/a/b").should be_true
end
+ it "write_archive works for paths with spaces" do
+ system "cd #{@sandbox_dir}; mkdir -p a; touch a/b; tar cf xfer.tar a; mkdir with\\ space"
+ archive = File.read("#{@sandbox_dir}/xfer.tar")
+ @con.write_archive(archive, "#{@sandbox_dir}/with space")
+ File.directory?("#{@sandbox_dir}/with space/a").should be_true
+ File.exists?("#{@sandbox_dir}/with space/a/b").should be_true
+ end
+
it "index fetches list of all files and dirs in a dir when pattern is empty" do
system "cd #{@sandbox_dir}; mkdir dir; touch file"
@con.index(@sandbox_dir, '').should == [ 'dir/', 'file' ]

0 comments on commit 80af992

Please sign in to comment.