Skip to content

Commit

Permalink
Auto merge of #1578 - e2:e2-install_symlinks_last_1577, r=segiddins
Browse files Browse the repository at this point in the history
Fix broken symlink support in tar writer (+ fix broken test)

# Description:

Fix for: #1577

(Avoids installing symlinks before symlink targets have been copied).

# Tasks:

- [X] Describe the problem / feature
- [ ] Write tests
- [X] Write code to solve the problem
- [ ] Get code review from coworkers / friends
- [ ] [Squash commits](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html)

I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md).
  • Loading branch information
homu committed May 21, 2016
2 parents 04d4d85 + 6cc7594 commit a757ce9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/rubygems/package.rb
Expand Up @@ -211,7 +211,9 @@ def add_files tar # :nodoc:
stat = File.lstat file

if stat.symlink?
tar.add_symlink file, File.readlink(file), stat.mode
relative_dir = File.dirname(file).sub("#{Dir.pwd}/", '')
target_path = File.join(relative_dir, File.readlink(file))
tar.add_symlink file, target_path, stat.mode
end

next unless stat.file?
Expand Down
12 changes: 9 additions & 3 deletions test/rubygems/test_gem_package.rb
Expand Up @@ -141,7 +141,9 @@ def test_add_files_symlink

FileUtils.mkdir_p 'lib'
open 'lib/code.rb', 'w' do |io| io.write '# lib/code.rb' end
File.symlink('lib/code.rb', 'lib/code_sym.rb')

# NOTE: 'code.rb' is correct, because it's relative to lib/code_sym.rb
File.symlink('code.rb', 'lib/code_sym.rb')

package = Gem::Package.new 'bogus.gem'
package.spec = spec
Expand All @@ -156,12 +158,16 @@ def test_add_files_symlink

Gem::Package::TarReader.new tar do |tar_io|
tar_io.each_entry do |entry|
(entry.symlink? ? symlinks : files) << entry.full_name
if entry.symlink?
symlinks << { entry.full_name => entry.header.linkname }
else
files << entry.full_name
end
end
end

assert_equal %w[lib/code.rb], files
assert_equal %w[lib/code_sym.rb], symlinks
assert_equal [{'lib/code_sym.rb' => 'lib/code.rb'}], symlinks
end

def test_build
Expand Down

0 comments on commit a757ce9

Please sign in to comment.