# Your deploy.rb contents here

task :update_code, :roles => [:app, :db, :web] do
  on_rollback { delete release_path, :recursive => true }

  # this directory will store our local copy of the code
  temp_dest = "to_deploy"
  
  # the name of our code tarball
  tgz = "to_deploy.tgz"

  # export the current code into the above directory
  system("svn export -q #{configuration.repository} #{temp_dest}")

  # create a tarball and send it to the server
  system("tar -C #{temp_dest} -czf #{tgz} .")
  put(File.read(tgz), tgz)

  # untar the code on the server
  run <<-CMD
  mkdir -p  #{release_path}             &&
  tar -C    #{release_path} -xzf #{tgz} 
  CMD

  # symlink the shared paths into our release directory
  run <<-CMD
    rm -rf #{release_path}/log #{release_path}/public/system    &&
    ln -nfs #{shared_path}/log #{release_path}/log              &&
    ln -nfs #{shared_path}/system #{release_path}/public/system
  CMD

  # clean up our archives
  run "rm -f #{tgz}"
  system("rm -rf #{temp_dest} #{tgz}")
end