Skip to content

Commit

Permalink
Create directory junctions instead of symlinks on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
rodjek committed Jun 6, 2017
1 parent 4bef869 commit 2852221
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/puppetlabs_spec_helper/rake_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ def max_thread_limit
puppet_symlink_available = Puppet::FileSystem.respond_to?(:symlink)
rescue
end
if is_windows
begin
require 'win32/dir'
rescue LoadError
$stderr.puts "win32-dir gem not installed, falling back to executing mklink directly"
end
end

# git has a race condition creating that directory, that would lead to aborted clone operations
FileUtils::mkdir_p("spec/fixtures/modules")
Expand Down Expand Up @@ -283,8 +290,17 @@ def max_thread_limit

fixtures("symlinks").each do |source, target|
if is_windows
fail "Cannot symlink on Windows unless using at least Puppet 3.5" if !puppet_symlink_available
Puppet::FileSystem::exist?(target) || Puppet::FileSystem::symlink(source, target)
if puppet_symlink_available
Puppet::FileSystem::exist?(target) || Puppet::FileSystem::symlink(source, target)
end

unless File.symlink?(target)
if Dir.respond_to?(:create_junction)
Dir.create_junction(target, source)
else
system("call mklink /J \"#{target.gsub('/', '\\')}\" \"#{source.gsub('/', '\\')}\"")
end
end
else
File::exists?(target) || FileUtils::ln_sf(source, target)
end
Expand Down

0 comments on commit 2852221

Please sign in to comment.