Skip to content

Commit

Permalink
Dir#purge destroys all contents
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Wiggins committed Mar 7, 2008
1 parent 8702559 commit 8bc4050
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/rush/dir.rb
Expand Up @@ -123,6 +123,11 @@ def bash(command)
box.bash "cd #{full_path} && #{command}"
end

# Destroy all of the contents of the directory, leaving it fresh and clean.
def purge
connection.purge full_path
end

# Text output of dir listing, equivalent to the regular unix shell's ls command.
def ls
out = [ "#{self}" ]
Expand Down
8 changes: 8 additions & 0 deletions lib/rush/local.rb
Expand Up @@ -35,6 +35,13 @@ def destroy(full_path)
true
end

# Purge the contents of a dir.
def purge(full_path)
raise "No." if full_path == '/'
FileUtils.rm_rf Dir.glob("#{full_path}/*")
true
end

# Create a dir.
def create_dir(full_path)
FileUtils.mkdir_p(full_path)
Expand Down Expand Up @@ -256,6 +263,7 @@ def receive(params)
when 'write_file' then write_file(params[:full_path], params[:payload])
when 'file_contents' then file_contents(params[:full_path])
when 'destroy' then destroy(params[:full_path])
when 'purge' then purge(params[:full_path])
when 'create_dir' then create_dir(params[:full_path])
when 'rename' then rename(params[:path], params[:name], params[:new_name])
when 'copy' then copy(params[:src], params[:dst])
Expand Down
4 changes: 4 additions & 0 deletions lib/rush/remote.rb
Expand Up @@ -26,6 +26,10 @@ def destroy(full_path)
transmit(:action => 'destroy', :full_path => full_path)
end

def purge(full_path)
transmit(:action => 'purge', :full_path => full_path)
end

def create_dir(full_path)
transmit(:action => 'create_dir', :full_path => full_path)
end
Expand Down
12 changes: 12 additions & 0 deletions spec/local_spec.rb
Expand Up @@ -27,6 +27,11 @@
@con.receive(:action => 'destroy', :full_path => 'file')
end

it "receive -> purge(dir)" do
@con.should_receive(:purge).with('dir')
@con.receive(:action => 'purge', :full_path => 'dir')
end

it "receive -> create_dir(path)" do
@con.should_receive(:create_dir).with('dir')
@con.receive(:action => 'create_dir', :full_path => 'dir')
Expand Down Expand Up @@ -116,6 +121,13 @@
File.exists?(fname).should be_false
end

it "purge to purge a dir" do
system "cd #{@sandbox_dir}; touch {1,2}; mkdir 3; touch 3/4"
@con.purge(@sandbox_dir)
File.exists?(@sandbox_dir).should be_true
Dir.glob("#{@sandbox_dir}/*").should == []
end

it "create_dir creates a directory" do
fname = "#{@sandbox_dir}/a/b/c/"
@con.create_dir(fname)
Expand Down
5 changes: 5 additions & 0 deletions spec/remote_spec.rb
Expand Up @@ -27,6 +27,11 @@
@con.destroy('file')
end

it "transmits purge" do
@con.should_receive(:transmit).with(:action => 'purge', :full_path => 'dir')
@con.purge('dir')
end

it "transmits create_dir" do
@con.should_receive(:transmit).with(:action => 'create_dir', :full_path => 'file')
@con.create_dir('file')
Expand Down

0 comments on commit 8bc4050

Please sign in to comment.