@@ -709,6 +709,77 @@ def extract_files(destination_dir, pattern = "*")
709709 end
710710
711711 class UnpackedInstaller < Gem ::Installer
712+ # This method is mostly copied from old version of Gem::Installer#install
713+ def install_with_default_gem
714+ verify_gem_home
715+
716+ # The name and require_paths must be verified first, since it could contain
717+ # ruby code that would be eval'ed in #ensure_loadable_spec
718+ verify_spec
719+
720+ ensure_loadable_spec
721+
722+ if options [ :install_as_default ]
723+ Gem . ensure_default_gem_subdirectories gem_home
724+ else
725+ Gem . ensure_gem_subdirectories gem_home
726+ end
727+
728+ return true if @force
729+
730+ ensure_dependencies_met unless @ignore_dependencies
731+
732+ run_pre_install_hooks
733+
734+ # Set loaded_from to ensure extension_dir is correct
735+ if @options [ :install_as_default ]
736+ spec . loaded_from = default_spec_file
737+ else
738+ spec . loaded_from = spec_file
739+ end
740+
741+ # Completely remove any previous gem files
742+ FileUtils . rm_rf gem_dir
743+ FileUtils . rm_rf spec . extension_dir
744+
745+ dir_mode = options [ :dir_mode ]
746+ FileUtils . mkdir_p gem_dir , mode : dir_mode && 0o755
747+
748+ if @options [ :install_as_default ]
749+ extract_bin
750+ write_default_spec
751+ else
752+ extract_files
753+
754+ build_extensions
755+ write_build_info_file
756+ run_post_build_hooks
757+ end
758+
759+ generate_bin
760+ generate_plugins
761+
762+ unless @options [ :install_as_default ]
763+ write_spec
764+ write_cache_file
765+ end
766+
767+ File . chmod ( dir_mode , gem_dir ) if dir_mode
768+
769+ say spec . post_install_message if options [ :post_install_message ] && !spec . post_install_message . nil?
770+
771+ Gem ::Specification . add_spec ( spec ) unless @install_dir
772+
773+ load_plugin
774+
775+ run_post_install_hooks
776+
777+ spec
778+ rescue Errno ::EACCES => e
779+ # Permission denied - /path/to/foo
780+ raise Gem ::FilePermissionError , e . message . split ( " - " ) . last
781+ end
782+
712783 def write_cache_file
713784 end
714785
@@ -754,7 +825,7 @@ def write_default_spec
754825 def install
755826 spec . post_install_message = nil
756827 dir_creating ( without_destdir ( gem_dir ) )
757- RbInstall . no_write ( options ) { super }
828+ RbInstall . no_write ( options ) { install_with_default_gem }
758829 end
759830
760831 # Now build-ext builds all extensions including bundled gems.
0 commit comments