class Gem::RemoteFetcher

def cache_update_path uri, path = nil, update = true

def cache_update_path uri, path = nil, update = true
  mtime = path && File.stat(path).mtime rescue nil
  data = fetch_path(uri, mtime)
  if data == nil # indicates the server returned 304 Not Modified
    return Gem.read_binary(path)
  end
  if update and path
    begin
      open(path, 'wb') do |io|
        io.flock(File::LOCK_EX)
        io.write data
      end
    rescue Errno::ENOLCK # NFS
      if Thread.main != Thread.current
        raise
      else
        open(path, 'wb') do |io|
          io.write data
        end
      end
    end
  end
  data
end