Permalink
Browse files

Don't put gem_bin_path in packages if there's no need.

This should fix #612.
  • Loading branch information...
1 parent 1f764b8 commit 3407b9a33f7f57c47ffc3b308aea1fcfa8f5f049 @jordansissel committed Jan 8, 2014
Showing with 12 additions and 0 deletions.
  1. +12 −0 lib/fpm/package/gem.rb
View
12 lib/fpm/package/gem.rb
@@ -186,6 +186,18 @@ def install_to_staging(gem_path)
::FileUtils.mkdir_p(bin_path)
args << gem_path
safesystem(*args)
+
+ # Delete bin_path if it's empty, and any empty parents (#612)
+ # Above, we mkdir_p bin_path because rubygems aborts if the parent
+ # directory doesn't exist, for example:
+ # ERROR: While executing gem ... (Errno::ENOENT)
+ # No such file or directory - /tmp/something/weird/bin
+ tmp = bin_path
+ while ::Dir.entries(tmp).size == 2 || tmp == "/" # just [ "..", "." ] is an empty directory
+ @logger.info("Deleting empty bin_path", :path => tmp)
+ ::Dir.rmdir(tmp)
+ tmp = File.dirname(tmp)
+ end
end # def install_to_staging
# Sanitize package name.

0 comments on commit 3407b9a

Please sign in to comment.