mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Merge pull request #27 from prathe/master.
Fix/Support relative path for copy_cache and copy_dir options.
This commit is contained in:
commit
1d64d7a939
2 changed files with 33 additions and 13 deletions
|
@ -58,9 +58,10 @@ module Capistrano
|
|||
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 @@ module Capistrano
|
|||
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 @@ module Capistrano
|
|||
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 @@ module Capistrano
|
|||
# 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 @@ module Capistrano
|
|||
# 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 @@ module Capistrano
|
|||
# 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 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|||
@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 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|||
@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 @@ class DeployStrategyCopyTest < Test::Unit::TestCase
|
|||
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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue