Permalink
Browse files

Merge pull request #27 from prathe/master.

Fix/Support relative path for copy_cache and copy_dir options.
  • Loading branch information...
2 parents f392faf + aa5518c commit 1d64d7a9391ed99205012a959f2c4986c4358df5 @leehambley leehambley committed May 3, 2011
Showing with 33 additions and 13 deletions.
  1. +11 −10 lib/capistrano/recipes/deploy/strategy/copy.rb
  2. +22 −3 test/deploy/strategy/copy_test.rb
@@ -58,9 +58,10 @@ def deploy!
raise Capistrano::Error, "shell command failed with return code #{$?}"
end
+ FileUtils.mkdir_p(destination)
+
logger.debug "copying cache to deployment staging area #{destination}"
Dir.chdir(copy_cache) do
- FileUtils.mkdir_p(destination)
queue = Dir.glob("*", File::FNM_DOTMATCH)
while queue.any?
item = queue.shift
@@ -70,12 +71,12 @@ def deploy!
next if copy_exclude.any? { |pattern| File.fnmatch(pattern, item) }
if File.symlink?(item)
- FileUtils.ln_s(File.readlink(File.join(copy_cache, item)), File.join(destination, item))
+ FileUtils.ln_s(File.readlink(item), File.join(destination, item))
elsif File.directory?(item)
queue += Dir.glob("#{item}/*", File::FNM_DOTMATCH)
FileUtils.mkdir(File.join(destination, item))
else
- FileUtils.ln(File.join(copy_cache, item), File.join(destination, item))
+ FileUtils.ln(item, File.join(destination, item))
end
end
end
@@ -99,7 +100,7 @@ def deploy!
File.open(File.join(destination, "REVISION"), "w") { |f| f.puts(revision) }
logger.trace "compressing #{destination} to #{filename}"
- Dir.chdir(tmpdir) { system(compress(File.basename(destination), File.basename(filename)).join(" ")) }
+ Dir.chdir(copy_dir) { system(compress(File.basename(destination), File.basename(filename)).join(" ")) }
distribute!
ensure
@@ -121,8 +122,8 @@ def check!
# is +true+, a default cache location will be returned.
def copy_cache
@copy_cache ||= configuration[:copy_cache] == true ?
- File.join(Dir.tmpdir, configuration[:application]) :
- configuration[:copy_cache]
+ File.expand_path(configuration[:application], Dir.tmpdir) :
+ File.expand_path(configuration[:copy_cache], Dir.pwd) rescue nil
end
private
@@ -136,7 +137,7 @@ def copy_exclude
# Returns the basename of the release_path, which will be used to
# name the local copy and archive file.
def destination
- @destination ||= File.join(tmpdir, File.basename(configuration[:release_path]))
+ @destination ||= File.join(copy_dir, File.basename(configuration[:release_path]))
end
# Returns the value of the :copy_strategy variable, defaulting to
@@ -159,12 +160,12 @@ def command
# Returns the name of the file that the source code will be
# compressed to.
def filename
- @filename ||= File.join(tmpdir, "#{File.basename(destination)}.#{compression.extension}")
+ @filename ||= File.join(copy_dir, "#{File.basename(destination)}.#{compression.extension}")
end
# The directory to which the copy should be checked out
- def tmpdir
- @tmpdir ||= configuration[:copy_dir] || Dir.tmpdir
+ def copy_dir
+ @copy_dir ||= File.expand_path(configuration[:copy_dir] || Dir.tmpdir, Dir.pwd)
end
# The directory on the remote server to which the archive should be
@@ -232,7 +232,7 @@ def test_with_copy_cache_should_update_cache_if_cache_exists_and_then_copy
@strategy.deploy!
end
- def test_with_copy_cache_with_custom_cache_dir_should_use_specified_cache_dir
+ def test_with_copy_cache_with_custom_absolute_cache_dir_path_should_use_specified_cache_dir
@config[:copy_cache] = "/u/caches/captest"
Dir.stubs(:tmpdir).returns("/temp/dir")
@@ -250,6 +250,25 @@ def test_with_copy_cache_with_custom_cache_dir_should_use_specified_cache_dir
@strategy.deploy!
end
+ def test_with_copy_cache_with_custom_relative_cache_dir_path_should_use_specified_cache_dir
+ @config[:copy_cache] = "caches/captest"
+
+ Dir.stubs(:pwd).returns("/u")
+ Dir.stubs(:tmpdir).returns("/temp/dir")
+ File.expects(:exists?).with("/u/caches/captest").returns(true)
+ Dir.expects(:chdir).with("/u/caches/captest").yields
+
+ @source.expects(:sync).with("154", "/u/caches/captest").returns(:local_sync)
+ @strategy.expects(:system).with(:local_sync)
+
+ FileUtils.expects(:mkdir_p).with("/temp/dir/1234567890")
+
+ prepare_directory_tree!("/u/caches/captest")
+
+ prepare_standard_compress_and_copy!
+ @strategy.deploy!
+ end
+
def test_with_copy_cache_with_excludes_should_not_copy_excluded_files
@config[:copy_cache] = true
@config[:copy_exclude] = "*/bar.txt"
@@ -276,13 +295,13 @@ def prepare_directory_tree!(cache, exclude=false)
File.expects(:directory?).with("app").returns(true)
FileUtils.expects(:mkdir).with("/temp/dir/1234567890/app")
File.expects(:directory?).with("foo.txt").returns(false)
- FileUtils.expects(:ln).with("#{cache}/foo.txt", "/temp/dir/1234567890/foo.txt")
+ FileUtils.expects(:ln).with("foo.txt", "/temp/dir/1234567890/foo.txt")
Dir.expects(:glob).with("app/*", File::FNM_DOTMATCH).returns(["app/.", "app/..", "app/bar.txt"])
unless exclude
File.expects(:directory?).with("app/bar.txt").returns(false)
- FileUtils.expects(:ln).with("#{cache}/app/bar.txt", "/temp/dir/1234567890/app/bar.txt")
+ FileUtils.expects(:ln).with("app/bar.txt", "/temp/dir/1234567890/app/bar.txt")
end
end

0 comments on commit 1d64d7a

Please sign in to comment.