Created
November 7, 2012 08:21
-
-
Save gussan/4030159 to your computer and use it in GitHub Desktop.
Gem::InstallerでErrno::EPERM: Operation not permittedが出るときの逃げ道
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# monkey patch for permission problem when installing package including executables from git repository | |
# (Errno::EPERM: Operation not permitted) | |
# for rubygems >= 1.8 | |
# 1. put this file under lib directory. | |
# 2. put below line to top of Gemfile. | |
# | |
# require File.expand_path("lib/gem_installer_eperm_patch", File.dirname(__FILE__)) | |
# | |
require 'rubygems/installer' | |
class Gem::Installer | |
def generate_bin | |
return if spec.executables.nil? or spec.executables.empty? | |
# If the user has asked for the gem to be installed in a directory that is | |
# the system gem directory, then use the system bin directory, else create | |
# (or use) a new bin dir under the gem_home. | |
bindir = @bin_dir || Gem.bindir(gem_home) | |
Dir.mkdir bindir unless File.exist? bindir | |
raise Gem::FilePermissionError.new(bindir) unless File.writable? bindir | |
spec.executables.each do |filename| | |
filename.untaint | |
bin_path = File.expand_path File.join(gem_dir, spec.bindir, filename) | |
unless File.exist? bin_path | |
warn "Hey?!?! Where did #{bin_path} go??" | |
next | |
end | |
if File.owned?(bin_path) | |
mode = File.stat(bin_path).mode | 0111 | |
FileUtils.chmod mode, bin_path | |
if @wrappers then | |
generate_bin_script filename, bindir | |
else | |
generate_bin_symlink filename, bindir | |
end | |
else | |
warn "#{bin_path} is owned by different user. chmod skipped." | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment