staging/lib/vcap/staging/plugin/node/npm_support/npm_package.rb
# This is done in a similar to ruby gems way until PackageCache is available
This is done in a similar to ruby gems way until PackageCache is available
This is done in a similar to ruby gems way until PackageCache is available
def fetch_build
    tmp_dir = Dir.mktmpdir
    at_exit do
      user = `whoami`.chomp
      `sudo /bin/chown -R #{user} #{tmp_dir}` if @secure_uid
      FileUtils.rm_rf(tmp_dir)
    end
    package_dir = fetch(@registry_data["source"], tmp_dir)
    return unless package_dir
    if @secure_uid
      chown_cmd = "sudo /bin/chown -R #{@secure_uid}:#{@secure_gid} #{tmp_dir} 2>&1"
      chown_output = `#{chown_cmd}`
      if $?.exitstatus != 0
        @logger.error("Failed chowning install dir: #{chown_output}")
        return nil
      end
    end
    cmd = @npm_helper.build_cmd(package_dir)
    if @secure_uid
      cmd ="sudo -u '##{@secure_uid}' sg #{secure_group} -c \"cd #{tmp_dir} && #{cmd}\" 2>&1"
    else
      cmd ="cd #{tmp_dir} && #{cmd}"
    end
    output = nil
    IO.popen(cmd) do |io|
      output = io.read
    end
    child_status = $?.exitstatus
    if child_status != 0
      @logger.warn("Failed installing package: #{@name}")
      if output =~ /npm not ok/
        output.lines.grep(/^npm ERR! message/) do |error_message|
          @logger.warn(error_message.chomp)
        end
      end
    end
    if @secure_uid
      `sudo -u '##{@secure_uid}' pkill -9 -U #{@secure_uid} 2>&1`
      me = `whoami`.chomp
      `sudo chown -R #{me} #{tmp_dir}`
      @logger.debug("Failed chowning #{tmp_dir} to #{me}") if $?.exitstatus != 0
    end
    return package_dir if child_status == 0
  end
def fetch_build tmp_dir = Dir . mktmpdir at_exit do user = ` whoami ` . chomp ` sudo /bin/chown -R  #{ user } #{ tmp_dir } ` if @secure_uid FileUtils . rm_rf ( tmp_dir ) end package_dir = fetch ( @registry_data [ "source" ] , tmp_dir ) return unless package_dir if @secure_uid chown_cmd = "sudo /bin/chown -R #{@secure_uid}:#{@secure_gid} #{tmp_dir} 2>&1" chown_output = ` #{ chown_cmd } ` if $? . exitstatus != 0 @logger . error ( "Failed chowning install dir: #{chown_output}" ) return nil end end cmd = @npm_helper . build_cmd ( package_dir ) if @secure_uid cmd = "sudo -u '##{@secure_uid}' sg #{secure_group} -c \"cd #{tmp_dir} && #{cmd}\" 2>&1" else cmd = "cd #{tmp_dir} && #{cmd}" end output = nil IO . popen ( cmd ) do | io | output = io . read end child_status = $? . exitstatus if child_status != 0 @logger . warn ( "Failed installing package: #{@name}" ) if output =~ / npm not ok / output . lines . grep ( / ^npm ERR! message / ) do | error_message | @logger . warn ( error_message . chomp ) end end end if @secure_uid ` sudo -u '# #{ @secure_uid } ' pkill -9 -U  #{ @secure_uid }  2>&1 ` me = ` whoami ` . chomp ` sudo chown -R  #{ me } #{ tmp_dir } ` @logger . debug ( "Failed chowning #{tmp_dir} to #{me}" ) if $? . exitstatus != 0 end return package_dir if child_status == 0 end
This is done in a similar to ruby gems way until PackageCache is available
This is done in a similar to ruby gems way until PackageCache is available
# Kill any stray processes that the npm compilation may have created