rubygems-update 2.6.0 → 3.4.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (804) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +5802 -0
  3. data/CODE_OF_CONDUCT.md +76 -35
  4. data/CONTRIBUTING.md +231 -0
  5. data/MAINTAINERS.txt +8 -0
  6. data/Manifest.txt +441 -42
  7. data/POLICIES.md +135 -0
  8. data/README.md +114 -0
  9. data/UPGRADING.md +15 -0
  10. data/bundler/CHANGELOG.md +4666 -0
  11. data/bundler/LICENSE.md +22 -0
  12. data/bundler/README.md +58 -0
  13. data/bundler/UPGRADING.md +222 -0
  14. data/bundler/bundler.gemspec +44 -0
  15. data/bundler/exe/bundle +38 -0
  16. data/bundler/exe/bundler +4 -0
  17. data/bundler/lib/bundler/.document +1 -0
  18. data/bundler/lib/bundler/build_metadata.rb +45 -0
  19. data/bundler/lib/bundler/capistrano.rb +22 -0
  20. data/bundler/lib/bundler/cli/add.rb +47 -0
  21. data/bundler/lib/bundler/cli/binstubs.rb +57 -0
  22. data/bundler/lib/bundler/cli/cache.rb +43 -0
  23. data/bundler/lib/bundler/cli/check.rb +40 -0
  24. data/bundler/lib/bundler/cli/clean.rb +25 -0
  25. data/bundler/lib/bundler/cli/common.rb +130 -0
  26. data/bundler/lib/bundler/cli/config.rb +203 -0
  27. data/bundler/lib/bundler/cli/console.rb +43 -0
  28. data/bundler/lib/bundler/cli/doctor.rb +157 -0
  29. data/bundler/lib/bundler/cli/exec.rb +88 -0
  30. data/bundler/lib/bundler/cli/fund.rb +36 -0
  31. data/bundler/lib/bundler/cli/gem.rb +466 -0
  32. data/bundler/lib/bundler/cli/info.rb +94 -0
  33. data/bundler/lib/bundler/cli/init.rb +51 -0
  34. data/bundler/lib/bundler/cli/inject.rb +60 -0
  35. data/bundler/lib/bundler/cli/install.rb +189 -0
  36. data/bundler/lib/bundler/cli/issue.rb +41 -0
  37. data/bundler/lib/bundler/cli/list.rb +66 -0
  38. data/bundler/lib/bundler/cli/lock.rb +73 -0
  39. data/bundler/lib/bundler/cli/open.rb +29 -0
  40. data/bundler/lib/bundler/cli/outdated.rb +297 -0
  41. data/bundler/lib/bundler/cli/platform.rb +48 -0
  42. data/bundler/lib/bundler/cli/plugin.rb +41 -0
  43. data/bundler/lib/bundler/cli/pristine.rb +52 -0
  44. data/bundler/lib/bundler/cli/remove.rb +17 -0
  45. data/bundler/lib/bundler/cli/show.rb +75 -0
  46. data/bundler/lib/bundler/cli/update.rb +123 -0
  47. data/bundler/lib/bundler/cli/viz.rb +31 -0
  48. data/bundler/lib/bundler/cli.rb +894 -0
  49. data/bundler/lib/bundler/compact_index_client/cache.rb +101 -0
  50. data/bundler/lib/bundler/compact_index_client/gem_parser.rb +28 -0
  51. data/bundler/lib/bundler/compact_index_client/updater.rb +117 -0
  52. data/bundler/lib/bundler/compact_index_client.rb +119 -0
  53. data/bundler/lib/bundler/constants.rb +7 -0
  54. data/bundler/lib/bundler/current_ruby.rb +108 -0
  55. data/bundler/lib/bundler/definition.rb +978 -0
  56. data/bundler/lib/bundler/dependency.rb +97 -0
  57. data/bundler/lib/bundler/deployment.rb +69 -0
  58. data/bundler/lib/bundler/deprecate.rb +44 -0
  59. data/bundler/lib/bundler/digest.rb +71 -0
  60. data/bundler/lib/bundler/dsl.rb +583 -0
  61. data/bundler/lib/bundler/endpoint_specification.rb +143 -0
  62. data/bundler/lib/bundler/env.rb +150 -0
  63. data/bundler/lib/bundler/environment_preserver.rb +86 -0
  64. data/bundler/lib/bundler/errors.rb +190 -0
  65. data/bundler/lib/bundler/feature_flag.rb +53 -0
  66. data/bundler/lib/bundler/fetcher/base.rb +50 -0
  67. data/bundler/lib/bundler/fetcher/compact_index.rb +129 -0
  68. data/bundler/lib/bundler/fetcher/dependency.rb +78 -0
  69. data/bundler/lib/bundler/fetcher/downloader.rb +89 -0
  70. data/bundler/lib/bundler/fetcher/index.rb +25 -0
  71. data/bundler/lib/bundler/fetcher.rb +321 -0
  72. data/bundler/lib/bundler/force_platform.rb +18 -0
  73. data/bundler/lib/bundler/friendly_errors.rb +126 -0
  74. data/bundler/lib/bundler/gem_helper.rb +237 -0
  75. data/bundler/lib/bundler/gem_helpers.rb +124 -0
  76. data/bundler/lib/bundler/gem_tasks.rb +7 -0
  77. data/bundler/lib/bundler/gem_version_promoter.rb +145 -0
  78. data/bundler/lib/bundler/graph.rb +152 -0
  79. data/bundler/lib/bundler/index.rb +206 -0
  80. data/bundler/lib/bundler/injector.rb +287 -0
  81. data/bundler/lib/bundler/inline.rb +73 -0
  82. data/bundler/lib/bundler/installer/gem_installer.rb +84 -0
  83. data/bundler/lib/bundler/installer/parallel_installer.rb +194 -0
  84. data/bundler/lib/bundler/installer/standalone.rb +117 -0
  85. data/bundler/lib/bundler/installer.rb +267 -0
  86. data/bundler/lib/bundler/lazy_specification.rb +163 -0
  87. data/bundler/lib/bundler/lockfile_generator.rb +95 -0
  88. data/bundler/lib/bundler/lockfile_parser.rb +218 -0
  89. data/bundler/lib/bundler/man/.document +1 -0
  90. data/bundler/lib/bundler/man/bundle-add.1 +82 -0
  91. data/bundler/lib/bundler/man/bundle-add.1.ronn +58 -0
  92. data/bundler/lib/bundler/man/bundle-binstubs.1 +42 -0
  93. data/bundler/lib/bundler/man/bundle-binstubs.1.ronn +41 -0
  94. data/bundler/lib/bundler/man/bundle-cache.1 +61 -0
  95. data/bundler/lib/bundler/man/bundle-cache.1.ronn +79 -0
  96. data/bundler/lib/bundler/man/bundle-check.1 +31 -0
  97. data/bundler/lib/bundler/man/bundle-check.1.ronn +26 -0
  98. data/bundler/lib/bundler/man/bundle-clean.1 +24 -0
  99. data/bundler/lib/bundler/man/bundle-clean.1.ronn +18 -0
  100. data/bundler/lib/bundler/man/bundle-config.1 +512 -0
  101. data/bundler/lib/bundler/man/bundle-config.1.ronn +405 -0
  102. data/bundler/lib/bundler/man/bundle-console.1 +53 -0
  103. data/bundler/lib/bundler/man/bundle-console.1.ronn +44 -0
  104. data/bundler/lib/bundler/man/bundle-doctor.1 +44 -0
  105. data/bundler/lib/bundler/man/bundle-doctor.1.ronn +33 -0
  106. data/bundler/lib/bundler/man/bundle-exec.1 +165 -0
  107. data/bundler/lib/bundler/man/bundle-exec.1.ronn +151 -0
  108. data/bundler/lib/bundler/man/bundle-gem.1 +105 -0
  109. data/bundler/lib/bundler/man/bundle-gem.1.ronn +117 -0
  110. data/bundler/lib/bundler/man/bundle-help.1 +13 -0
  111. data/bundler/lib/bundler/man/bundle-help.1.ronn +12 -0
  112. data/bundler/lib/bundler/man/bundle-info.1 +20 -0
  113. data/bundler/lib/bundler/man/bundle-info.1.ronn +17 -0
  114. data/bundler/lib/bundler/man/bundle-init.1 +29 -0
  115. data/bundler/lib/bundler/man/bundle-init.1.ronn +31 -0
  116. data/bundler/lib/bundler/man/bundle-inject.1 +36 -0
  117. data/bundler/lib/bundler/man/bundle-inject.1.ronn +24 -0
  118. data/bundler/lib/bundler/man/bundle-install.1 +313 -0
  119. data/bundler/lib/bundler/man/bundle-install.1.ronn +382 -0
  120. data/bundler/lib/bundler/man/bundle-list.1 +50 -0
  121. data/bundler/lib/bundler/man/bundle-list.1.ronn +33 -0
  122. data/bundler/lib/bundler/man/bundle-lock.1 +84 -0
  123. data/bundler/lib/bundler/man/bundle-lock.1.ronn +94 -0
  124. data/bundler/lib/bundler/man/bundle-open.1 +52 -0
  125. data/bundler/lib/bundler/man/bundle-open.1.ronn +27 -0
  126. data/bundler/lib/bundler/man/bundle-outdated.1 +152 -0
  127. data/bundler/lib/bundler/man/bundle-outdated.1.ronn +105 -0
  128. data/bundler/lib/bundler/man/bundle-platform.1 +71 -0
  129. data/bundler/lib/bundler/man/bundle-platform.1.ronn +49 -0
  130. data/bundler/lib/bundler/man/bundle-plugin.1 +81 -0
  131. data/bundler/lib/bundler/man/bundle-plugin.1.ronn +59 -0
  132. data/bundler/lib/bundler/man/bundle-pristine.1 +34 -0
  133. data/bundler/lib/bundler/man/bundle-pristine.1.ronn +34 -0
  134. data/bundler/lib/bundler/man/bundle-remove.1 +31 -0
  135. data/bundler/lib/bundler/man/bundle-remove.1.ronn +23 -0
  136. data/bundler/lib/bundler/man/bundle-show.1 +23 -0
  137. data/bundler/lib/bundler/man/bundle-show.1.ronn +21 -0
  138. data/bundler/lib/bundler/man/bundle-update.1 +394 -0
  139. data/bundler/lib/bundler/man/bundle-update.1.ronn +351 -0
  140. data/bundler/lib/bundler/man/bundle-version.1 +35 -0
  141. data/bundler/lib/bundler/man/bundle-version.1.ronn +24 -0
  142. data/bundler/lib/bundler/man/bundle-viz.1 +42 -0
  143. data/bundler/lib/bundler/man/bundle-viz.1.ronn +32 -0
  144. data/bundler/lib/bundler/man/bundle.1 +141 -0
  145. data/bundler/lib/bundler/man/bundle.1.ronn +116 -0
  146. data/bundler/lib/bundler/man/gemfile.5 +747 -0
  147. data/bundler/lib/bundler/man/gemfile.5.ronn +548 -0
  148. data/bundler/lib/bundler/man/index.txt +29 -0
  149. data/bundler/lib/bundler/match_metadata.rb +13 -0
  150. data/bundler/lib/bundler/match_platform.rb +23 -0
  151. data/bundler/lib/bundler/match_remote_metadata.rb +29 -0
  152. data/bundler/lib/bundler/mirror.rb +221 -0
  153. data/bundler/lib/bundler/plugin/api/source.rb +320 -0
  154. data/bundler/lib/bundler/plugin/api.rb +81 -0
  155. data/bundler/lib/bundler/plugin/dsl.rb +53 -0
  156. data/bundler/lib/bundler/plugin/events.rb +61 -0
  157. data/bundler/lib/bundler/plugin/index.rb +193 -0
  158. data/bundler/lib/bundler/plugin/installer/git.rb +34 -0
  159. data/bundler/lib/bundler/plugin/installer/rubygems.rb +19 -0
  160. data/bundler/lib/bundler/plugin/installer.rb +112 -0
  161. data/bundler/lib/bundler/plugin/source_list.rb +31 -0
  162. data/bundler/lib/bundler/plugin.rb +359 -0
  163. data/bundler/lib/bundler/process_lock.rb +24 -0
  164. data/bundler/lib/bundler/remote_specification.rb +117 -0
  165. data/bundler/lib/bundler/resolver/base.rb +107 -0
  166. data/bundler/lib/bundler/resolver/candidate.rb +94 -0
  167. data/bundler/lib/bundler/resolver/incompatibility.rb +15 -0
  168. data/bundler/lib/bundler/resolver/package.rb +77 -0
  169. data/bundler/lib/bundler/resolver/root.rb +25 -0
  170. data/bundler/lib/bundler/resolver/spec_group.rb +82 -0
  171. data/bundler/lib/bundler/resolver.rb +462 -0
  172. data/bundler/lib/bundler/retry.rb +66 -0
  173. data/bundler/lib/bundler/ruby_dsl.rb +45 -0
  174. data/bundler/lib/bundler/ruby_version.rb +131 -0
  175. data/bundler/lib/bundler/rubygems_ext.rb +354 -0
  176. data/bundler/lib/bundler/rubygems_gem_installer.rb +187 -0
  177. data/bundler/lib/bundler/rubygems_integration.rb +562 -0
  178. data/bundler/lib/bundler/runtime.rb +307 -0
  179. data/bundler/lib/bundler/safe_marshal.rb +31 -0
  180. data/bundler/lib/bundler/self_manager.rb +170 -0
  181. data/bundler/lib/bundler/settings/validator.rb +102 -0
  182. data/bundler/lib/bundler/settings.rb +568 -0
  183. data/bundler/lib/bundler/setup.rb +30 -0
  184. data/bundler/lib/bundler/shared_helpers.rb +358 -0
  185. data/bundler/lib/bundler/similarity_detector.rb +63 -0
  186. data/bundler/lib/bundler/source/gemspec.rb +18 -0
  187. data/bundler/lib/bundler/source/git/git_proxy.rb +455 -0
  188. data/bundler/lib/bundler/source/git.rb +379 -0
  189. data/bundler/lib/bundler/source/metadata.rb +62 -0
  190. data/bundler/lib/bundler/source/path/installer.rb +53 -0
  191. data/bundler/lib/bundler/source/path.rb +260 -0
  192. data/bundler/lib/bundler/source/rubygems/remote.rb +68 -0
  193. data/bundler/lib/bundler/source/rubygems.rb +509 -0
  194. data/bundler/lib/bundler/source/rubygems_aggregate.rb +68 -0
  195. data/bundler/lib/bundler/source.rb +114 -0
  196. data/bundler/lib/bundler/source_list.rb +227 -0
  197. data/bundler/lib/bundler/source_map.rb +71 -0
  198. data/bundler/lib/bundler/spec_set.rb +219 -0
  199. data/bundler/lib/bundler/stub_specification.rb +118 -0
  200. data/bundler/lib/bundler/templates/.document +1 -0
  201. data/bundler/lib/bundler/templates/Executable +27 -0
  202. data/bundler/lib/bundler/templates/Executable.bundler +109 -0
  203. data/bundler/lib/bundler/templates/Executable.standalone +14 -0
  204. data/bundler/lib/bundler/templates/Gemfile +5 -0
  205. data/bundler/lib/bundler/templates/newgem/CHANGELOG.md.tt +5 -0
  206. data/bundler/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +84 -0
  207. data/bundler/lib/bundler/templates/newgem/Cargo.toml.tt +7 -0
  208. data/bundler/lib/bundler/templates/newgem/Gemfile.tt +26 -0
  209. data/bundler/lib/bundler/templates/newgem/LICENSE.txt.tt +21 -0
  210. data/bundler/lib/bundler/templates/newgem/README.md.tt +45 -0
  211. data/bundler/lib/bundler/templates/newgem/Rakefile.tt +71 -0
  212. data/bundler/lib/bundler/templates/newgem/bin/console.tt +11 -0
  213. data/bundler/lib/bundler/templates/newgem/bin/setup.tt +8 -0
  214. data/bundler/lib/bundler/templates/newgem/circleci/config.yml.tt +25 -0
  215. data/bundler/lib/bundler/templates/newgem/exe/newgem.tt +3 -0
  216. data/bundler/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt +15 -0
  217. data/bundler/lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt +10 -0
  218. data/bundler/lib/bundler/templates/newgem/ext/newgem/extconf-rust.rb.tt +6 -0
  219. data/bundler/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +9 -0
  220. data/bundler/lib/bundler/templates/newgem/ext/newgem/newgem.h.tt +6 -0
  221. data/bundler/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt +12 -0
  222. data/bundler/lib/bundler/templates/newgem/github/workflows/main.yml.tt +37 -0
  223. data/bundler/lib/bundler/templates/newgem/gitignore.tt +23 -0
  224. data/bundler/lib/bundler/templates/newgem/gitlab-ci.yml.tt +18 -0
  225. data/bundler/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +9 -0
  226. data/bundler/lib/bundler/templates/newgem/lib/newgem.rb.tt +15 -0
  227. data/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt +51 -0
  228. data/bundler/lib/bundler/templates/newgem/rspec.tt +3 -0
  229. data/bundler/lib/bundler/templates/newgem/rubocop.yml.tt +13 -0
  230. data/bundler/lib/bundler/templates/newgem/sig/newgem.rbs.tt +8 -0
  231. data/bundler/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +11 -0
  232. data/bundler/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +15 -0
  233. data/bundler/lib/bundler/templates/newgem/standard.yml.tt +3 -0
  234. data/bundler/lib/bundler/templates/newgem/test/minitest/test_helper.rb.tt +6 -0
  235. data/bundler/lib/bundler/templates/newgem/test/minitest/test_newgem.rb.tt +13 -0
  236. data/bundler/lib/bundler/templates/newgem/test/test-unit/newgem_test.rb.tt +15 -0
  237. data/bundler/lib/bundler/templates/newgem/test/test-unit/test_helper.rb.tt +6 -0
  238. data/bundler/lib/bundler/ui/rg_proxy.rb +19 -0
  239. data/bundler/lib/bundler/ui/shell.rb +165 -0
  240. data/bundler/lib/bundler/ui/silent.rb +85 -0
  241. data/bundler/lib/bundler/ui.rb +9 -0
  242. data/bundler/lib/bundler/uri_credentials_filter.rb +43 -0
  243. data/bundler/lib/bundler/uri_normalizer.rb +23 -0
  244. data/bundler/lib/bundler/vendor/.document +1 -0
  245. data/bundler/lib/bundler/vendor/connection_pool/LICENSE +20 -0
  246. data/bundler/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb +174 -0
  247. data/bundler/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb +3 -0
  248. data/bundler/lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb +56 -0
  249. data/bundler/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +128 -0
  250. data/bundler/lib/bundler/vendor/fileutils/LICENSE.txt +22 -0
  251. data/bundler/lib/bundler/vendor/fileutils/lib/fileutils.rb +2706 -0
  252. data/bundler/lib/bundler/vendor/net-http-persistent/README.rdoc +82 -0
  253. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/connection.rb +41 -0
  254. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb +65 -0
  255. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb +79 -0
  256. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +1073 -0
  257. data/bundler/lib/bundler/vendor/pub_grub/LICENSE.txt +21 -0
  258. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/assignment.rb +20 -0
  259. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/basic_package_source.rb +189 -0
  260. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/failure_writer.rb +182 -0
  261. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/incompatibility.rb +150 -0
  262. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/package.rb +43 -0
  263. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb +121 -0
  264. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/rubygems.rb +45 -0
  265. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/solve_failure.rb +19 -0
  266. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb +60 -0
  267. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb +105 -0
  268. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/version.rb +3 -0
  269. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb +129 -0
  270. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb +411 -0
  271. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb +248 -0
  272. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb +178 -0
  273. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub.rb +31 -0
  274. data/bundler/lib/bundler/vendor/thor/LICENSE.md +20 -0
  275. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +105 -0
  276. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb +61 -0
  277. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +108 -0
  278. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb +143 -0
  279. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +373 -0
  280. data/bundler/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +130 -0
  281. data/bundler/lib/bundler/vendor/thor/lib/thor/actions.rb +340 -0
  282. data/bundler/lib/bundler/vendor/thor/lib/thor/base.rb +825 -0
  283. data/bundler/lib/bundler/vendor/thor/lib/thor/command.rb +151 -0
  284. data/bundler/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +107 -0
  285. data/bundler/lib/bundler/vendor/thor/lib/thor/error.rb +106 -0
  286. data/bundler/lib/bundler/vendor/thor/lib/thor/group.rb +281 -0
  287. data/bundler/lib/bundler/vendor/thor/lib/thor/invocation.rb +178 -0
  288. data/bundler/lib/bundler/vendor/thor/lib/thor/line_editor/basic.rb +37 -0
  289. data/bundler/lib/bundler/vendor/thor/lib/thor/line_editor/readline.rb +88 -0
  290. data/bundler/lib/bundler/vendor/thor/lib/thor/line_editor.rb +17 -0
  291. data/bundler/lib/bundler/vendor/thor/lib/thor/nested_context.rb +29 -0
  292. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/argument.rb +89 -0
  293. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +195 -0
  294. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/option.rb +178 -0
  295. data/bundler/lib/bundler/vendor/thor/lib/thor/parser/options.rb +293 -0
  296. data/bundler/lib/bundler/vendor/thor/lib/thor/parser.rb +4 -0
  297. data/bundler/lib/bundler/vendor/thor/lib/thor/rake_compat.rb +72 -0
  298. data/bundler/lib/bundler/vendor/thor/lib/thor/runner.rb +335 -0
  299. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +388 -0
  300. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/color.rb +115 -0
  301. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb +29 -0
  302. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/html.rb +84 -0
  303. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/lcs_diff.rb +49 -0
  304. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/table_printer.rb +134 -0
  305. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/terminal.rb +42 -0
  306. data/bundler/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb +38 -0
  307. data/bundler/lib/bundler/vendor/thor/lib/thor/shell.rb +81 -0
  308. data/bundler/lib/bundler/vendor/thor/lib/thor/util.rb +285 -0
  309. data/bundler/lib/bundler/vendor/thor/lib/thor/version.rb +3 -0
  310. data/bundler/lib/bundler/vendor/thor/lib/thor.rb +663 -0
  311. data/bundler/lib/bundler/vendor/tsort/LICENSE.txt +22 -0
  312. data/bundler/lib/bundler/vendor/tsort/lib/tsort.rb +452 -0
  313. data/bundler/lib/bundler/vendor/uri/LICENSE.txt +22 -0
  314. data/bundler/lib/bundler/vendor/uri/lib/uri/common.rb +729 -0
  315. data/bundler/lib/bundler/vendor/uri/lib/uri/file.rb +100 -0
  316. data/bundler/lib/bundler/vendor/uri/lib/uri/ftp.rb +267 -0
  317. data/bundler/lib/bundler/vendor/uri/lib/uri/generic.rb +1587 -0
  318. data/bundler/lib/bundler/vendor/uri/lib/uri/http.rb +125 -0
  319. data/bundler/lib/bundler/vendor/uri/lib/uri/https.rb +23 -0
  320. data/bundler/lib/bundler/vendor/uri/lib/uri/ldap.rb +261 -0
  321. data/bundler/lib/bundler/vendor/uri/lib/uri/ldaps.rb +22 -0
  322. data/bundler/lib/bundler/vendor/uri/lib/uri/mailto.rb +293 -0
  323. data/bundler/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb +539 -0
  324. data/bundler/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb +119 -0
  325. data/bundler/lib/bundler/vendor/uri/lib/uri/version.rb +6 -0
  326. data/bundler/lib/bundler/vendor/uri/lib/uri/ws.rb +83 -0
  327. data/bundler/lib/bundler/vendor/uri/lib/uri/wss.rb +23 -0
  328. data/bundler/lib/bundler/vendor/uri/lib/uri.rb +104 -0
  329. data/bundler/lib/bundler/vendored_fileutils.rb +4 -0
  330. data/bundler/lib/bundler/vendored_persistent.rb +15 -0
  331. data/bundler/lib/bundler/vendored_pub_grub.rb +4 -0
  332. data/bundler/lib/bundler/vendored_thor.rb +8 -0
  333. data/bundler/lib/bundler/vendored_tsort.rb +4 -0
  334. data/bundler/lib/bundler/vendored_uri.rb +4 -0
  335. data/bundler/lib/bundler/version.rb +13 -0
  336. data/bundler/lib/bundler/vlad.rb +17 -0
  337. data/bundler/lib/bundler/worker.rb +117 -0
  338. data/bundler/lib/bundler/yaml_serializer.rb +93 -0
  339. data/bundler/lib/bundler.rb +654 -0
  340. data/{test/rubygems/bogussources.rb → exe/gem} +5 -2
  341. data/exe/update_rubygems +38 -0
  342. data/hide_lib_for_update/note.txt +0 -4
  343. data/lib/rubygems/available_set.rb +9 -9
  344. data/lib/rubygems/basic_specification.rb +56 -37
  345. data/lib/rubygems/bundler_version_finder.rb +77 -0
  346. data/lib/rubygems/command.rb +142 -67
  347. data/lib/rubygems/command_manager.rb +61 -25
  348. data/lib/rubygems/commands/build_command.rb +88 -17
  349. data/lib/rubygems/commands/cert_command.rb +131 -82
  350. data/lib/rubygems/commands/check_command.rb +27 -24
  351. data/lib/rubygems/commands/cleanup_command.rb +56 -37
  352. data/lib/rubygems/commands/contents_command.rb +33 -35
  353. data/lib/rubygems/commands/dependency_command.rb +52 -63
  354. data/lib/rubygems/commands/environment_command.rb +31 -13
  355. data/lib/rubygems/commands/exec_command.rb +249 -0
  356. data/lib/rubygems/commands/fetch_command.rb +36 -19
  357. data/lib/rubygems/commands/generate_index_command.rb +21 -20
  358. data/lib/rubygems/commands/help_command.rb +21 -21
  359. data/lib/rubygems/commands/info_command.rb +38 -0
  360. data/lib/rubygems/commands/install_command.rb +65 -133
  361. data/lib/rubygems/commands/list_command.rb +10 -9
  362. data/lib/rubygems/commands/lock_command.rb +11 -13
  363. data/lib/rubygems/commands/mirror_command.rb +4 -4
  364. data/lib/rubygems/commands/open_command.rb +28 -26
  365. data/lib/rubygems/commands/outdated_command.rb +6 -6
  366. data/lib/rubygems/commands/owner_command.rb +50 -26
  367. data/lib/rubygems/commands/pristine_command.rb +96 -66
  368. data/lib/rubygems/commands/push_command.rb +52 -45
  369. data/lib/rubygems/commands/query_command.rb +22 -328
  370. data/lib/rubygems/commands/rdoc_command.rb +31 -31
  371. data/lib/rubygems/commands/search_command.rb +9 -9
  372. data/lib/rubygems/commands/server_command.rb +15 -76
  373. data/lib/rubygems/commands/setup_command.rb +375 -188
  374. data/lib/rubygems/commands/signin_command.rb +34 -0
  375. data/lib/rubygems/commands/signout_command.rb +32 -0
  376. data/lib/rubygems/commands/sources_command.rb +51 -35
  377. data/lib/rubygems/commands/specification_command.rb +39 -29
  378. data/lib/rubygems/commands/stale_command.rb +5 -4
  379. data/lib/rubygems/commands/uninstall_command.rb +94 -59
  380. data/lib/rubygems/commands/unpack_command.rb +43 -52
  381. data/lib/rubygems/commands/update_command.rb +154 -96
  382. data/lib/rubygems/commands/which_command.rb +13 -16
  383. data/lib/rubygems/commands/yank_command.rb +27 -31
  384. data/lib/rubygems/compatibility.rb +8 -26
  385. data/lib/rubygems/config_file.rb +214 -119
  386. data/lib/rubygems/core_ext/kernel_gem.rb +10 -14
  387. data/lib/rubygems/core_ext/kernel_require.rb +119 -88
  388. data/lib/rubygems/core_ext/kernel_warn.rb +49 -0
  389. data/lib/rubygems/core_ext/tcpsocket_init.rb +54 -0
  390. data/lib/rubygems/defaults.rb +174 -56
  391. data/lib/rubygems/dependency.rb +66 -51
  392. data/lib/rubygems/dependency_installer.rb +70 -225
  393. data/lib/rubygems/dependency_list.rb +32 -33
  394. data/lib/rubygems/deprecate.rb +112 -17
  395. data/lib/rubygems/doctor.rb +30 -30
  396. data/lib/rubygems/errors.rb +51 -9
  397. data/lib/rubygems/exceptions.rb +64 -35
  398. data/lib/rubygems/ext/build_error.rb +3 -1
  399. data/lib/rubygems/ext/builder.rb +96 -75
  400. data/lib/rubygems/ext/cargo_builder/link_flag_converter.rb +27 -0
  401. data/lib/rubygems/ext/cargo_builder.rb +360 -0
  402. data/lib/rubygems/ext/cmake_builder.rb +6 -7
  403. data/lib/rubygems/ext/configure_builder.rb +6 -9
  404. data/lib/rubygems/ext/ext_conf_builder.rb +41 -60
  405. data/lib/rubygems/ext/rake_builder.rb +18 -21
  406. data/lib/rubygems/ext.rb +8 -7
  407. data/lib/rubygems/gem_runner.rb +22 -24
  408. data/lib/rubygems/gemcutter_utilities/webauthn_listener/response.rb +163 -0
  409. data/lib/rubygems/gemcutter_utilities/webauthn_listener.rb +105 -0
  410. data/lib/rubygems/gemcutter_utilities/webauthn_poller.rb +78 -0
  411. data/lib/rubygems/gemcutter_utilities.rb +244 -40
  412. data/lib/rubygems/indexer.rb +49 -55
  413. data/lib/rubygems/install_default_message.rb +3 -3
  414. data/lib/rubygems/install_message.rb +3 -3
  415. data/lib/rubygems/install_update_options.rb +103 -96
  416. data/lib/rubygems/installer.rb +370 -214
  417. data/lib/rubygems/installer_uninstaller_utils.rb +29 -0
  418. data/lib/rubygems/local_remote_options.rb +27 -27
  419. data/lib/rubygems/mock_gem_ui.rb +6 -9
  420. data/lib/rubygems/name_tuple.rb +16 -19
  421. data/lib/rubygems/openssl.rb +7 -0
  422. data/lib/rubygems/optparse/.document +1 -0
  423. data/lib/rubygems/optparse/COPYING +56 -0
  424. data/lib/rubygems/optparse/lib/optionparser.rb +2 -0
  425. data/lib/rubygems/optparse/lib/optparse/ac.rb +54 -0
  426. data/lib/rubygems/optparse/lib/optparse/date.rb +18 -0
  427. data/lib/rubygems/optparse/lib/optparse/kwargs.rb +22 -0
  428. data/lib/rubygems/optparse/lib/optparse/shellwords.rb +7 -0
  429. data/lib/rubygems/optparse/lib/optparse/time.rb +11 -0
  430. data/lib/rubygems/optparse/lib/optparse/uri.rb +7 -0
  431. data/lib/rubygems/optparse/lib/optparse/version.rb +71 -0
  432. data/lib/rubygems/optparse/lib/optparse.rb +2308 -0
  433. data/lib/rubygems/optparse.rb +3 -0
  434. data/lib/rubygems/package/digest_io.rb +5 -7
  435. data/lib/rubygems/package/file_source.rb +6 -8
  436. data/lib/rubygems/package/io_source.rb +6 -4
  437. data/lib/rubygems/package/old.rb +18 -27
  438. data/lib/rubygems/package/source.rb +1 -1
  439. data/lib/rubygems/package/tar_header.rb +86 -71
  440. data/lib/rubygems/package/tar_reader/entry.rb +113 -20
  441. data/lib/rubygems/package/tar_reader.rb +13 -37
  442. data/lib/rubygems/package/tar_writer.rb +28 -44
  443. data/lib/rubygems/package.rb +234 -135
  444. data/lib/rubygems/package_task.rb +6 -12
  445. data/lib/rubygems/path_support.rb +18 -12
  446. data/lib/rubygems/platform.rb +123 -77
  447. data/lib/rubygems/psych_tree.rb +3 -2
  448. data/lib/rubygems/query_utils.rb +351 -0
  449. data/lib/rubygems/rdoc.rb +4 -326
  450. data/lib/rubygems/remote_fetcher.rb +89 -171
  451. data/lib/rubygems/request/connection_pools.rb +30 -23
  452. data/lib/rubygems/request/http_pool.rb +6 -7
  453. data/lib/rubygems/request/https_pool.rb +2 -3
  454. data/lib/rubygems/request.rb +88 -41
  455. data/lib/rubygems/request_set/gem_dependency_api.rb +171 -176
  456. data/lib/rubygems/request_set/lockfile/parser.rb +39 -49
  457. data/lib/rubygems/request_set/lockfile/tokenizer.rb +15 -13
  458. data/lib/rubygems/request_set/lockfile.rb +34 -32
  459. data/lib/rubygems/request_set.rb +115 -71
  460. data/lib/rubygems/requirement.rb +72 -63
  461. data/lib/rubygems/resolver/activation_request.rb +35 -60
  462. data/lib/rubygems/resolver/api_set/gem_parser.rb +20 -0
  463. data/lib/rubygems/resolver/api_set.rb +40 -32
  464. data/lib/rubygems/resolver/api_specification.rb +37 -18
  465. data/lib/rubygems/resolver/best_set.rb +15 -17
  466. data/lib/rubygems/resolver/composed_set.rb +9 -11
  467. data/lib/rubygems/resolver/conflict.rb +18 -24
  468. data/lib/rubygems/resolver/current_set.rb +2 -4
  469. data/lib/rubygems/resolver/dependency_request.rb +8 -9
  470. data/lib/rubygems/resolver/git_set.rb +8 -10
  471. data/lib/rubygems/resolver/git_specification.rb +11 -13
  472. data/lib/rubygems/resolver/index_set.rb +10 -12
  473. data/lib/rubygems/resolver/index_specification.rb +42 -11
  474. data/lib/rubygems/resolver/installed_specification.rb +9 -11
  475. data/lib/rubygems/resolver/installer_set.rb +93 -46
  476. data/lib/rubygems/resolver/local_specification.rb +5 -7
  477. data/lib/rubygems/resolver/lock_set.rb +13 -15
  478. data/lib/rubygems/resolver/lock_specification.rb +13 -15
  479. data/lib/rubygems/resolver/molinillo/LICENSE +9 -0
  480. data/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/resolution_state.rb +57 -0
  481. data/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider.rb +88 -0
  482. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/action.rb +36 -0
  483. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +66 -0
  484. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +62 -0
  485. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +63 -0
  486. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +61 -0
  487. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/log.rb +126 -0
  488. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/set_payload.rb +46 -0
  489. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/tag.rb +36 -0
  490. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb +164 -0
  491. data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb +110 -146
  492. data/lib/rubygems/resolver/molinillo/lib/molinillo/errors.rb +83 -9
  493. data/lib/rubygems/resolver/molinillo/lib/molinillo/gem_metadata.rb +2 -1
  494. data/lib/rubygems/resolver/molinillo/lib/molinillo/modules/specification_provider.rb +13 -1
  495. data/lib/rubygems/resolver/molinillo/lib/molinillo/modules/ui.rb +3 -1
  496. data/lib/rubygems/resolver/molinillo/lib/molinillo/resolution.rb +552 -172
  497. data/lib/rubygems/resolver/molinillo/lib/molinillo/resolver.rb +3 -2
  498. data/lib/rubygems/resolver/molinillo/lib/molinillo/state.rb +12 -6
  499. data/lib/rubygems/resolver/molinillo/lib/molinillo.rb +6 -5
  500. data/lib/rubygems/resolver/molinillo.rb +2 -1
  501. data/lib/rubygems/resolver/requirement_list.rb +2 -2
  502. data/lib/rubygems/resolver/set.rb +3 -5
  503. data/lib/rubygems/resolver/source_set.rb +6 -7
  504. data/lib/rubygems/resolver/spec_specification.rb +16 -4
  505. data/lib/rubygems/resolver/specification.rb +25 -10
  506. data/lib/rubygems/resolver/stats.rb +1 -0
  507. data/lib/rubygems/resolver/vendor_set.rb +6 -8
  508. data/lib/rubygems/resolver/vendor_specification.rb +6 -8
  509. data/lib/rubygems/resolver.rb +120 -64
  510. data/lib/rubygems/s3_uri_signer.rb +177 -0
  511. data/lib/rubygems/safe_yaml.rb +59 -0
  512. data/lib/rubygems/security/policies.rb +49 -49
  513. data/lib/rubygems/security/policy.rb +44 -47
  514. data/lib/rubygems/security/signer.rb +86 -29
  515. data/lib/rubygems/security/trust_dir.rb +21 -23
  516. data/lib/rubygems/security.rb +111 -78
  517. data/lib/rubygems/security_option.rb +43 -0
  518. data/lib/rubygems/shellwords.rb +3 -0
  519. data/lib/rubygems/source/git.rb +40 -40
  520. data/lib/rubygems/source/installed.rb +5 -7
  521. data/lib/rubygems/source/local.rb +30 -30
  522. data/lib/rubygems/source/lock.rb +9 -7
  523. data/lib/rubygems/source/specific_file.rb +7 -8
  524. data/lib/rubygems/source/vendor.rb +3 -5
  525. data/lib/rubygems/source.rb +73 -63
  526. data/lib/rubygems/source_list.rb +14 -18
  527. data/lib/rubygems/spec_fetcher.rb +66 -78
  528. data/lib/rubygems/specification.rb +823 -1092
  529. data/lib/rubygems/specification_policy.rb +508 -0
  530. data/lib/rubygems/ssl_certs/rubygems.org/GlobalSignRootCA.pem +21 -0
  531. data/lib/rubygems/ssl_certs/rubygems.org/GlobalSignRootCA_R3.pem +21 -0
  532. data/lib/rubygems/stub_specification.rb +52 -53
  533. data/lib/rubygems/text.rb +40 -27
  534. data/lib/rubygems/tsort/.document +1 -0
  535. data/lib/rubygems/tsort/LICENSE.txt +22 -0
  536. data/lib/rubygems/tsort/lib/tsort.rb +452 -0
  537. data/lib/rubygems/tsort.rb +3 -0
  538. data/lib/rubygems/uninstaller.rb +149 -84
  539. data/lib/rubygems/unknown_command_spell_checker.rb +21 -0
  540. data/lib/rubygems/update_suggestion.rb +69 -0
  541. data/lib/rubygems/uri.rb +126 -0
  542. data/lib/rubygems/uri_formatter.rb +3 -6
  543. data/lib/rubygems/user_interaction.rb +95 -143
  544. data/lib/rubygems/util/licenses.rb +679 -314
  545. data/lib/rubygems/util/list.rb +2 -1
  546. data/lib/rubygems/util.rb +58 -73
  547. data/lib/rubygems/validator.rb +23 -47
  548. data/lib/rubygems/version.rb +92 -48
  549. data/lib/rubygems/version_option.rb +20 -9
  550. data/lib/rubygems/yaml_serializer.rb +93 -0
  551. data/lib/rubygems.rb +434 -346
  552. data/rubygems-update.gemspec +38 -0
  553. data/setup.rb +13 -27
  554. data/test/rubygems/alternate_cert.pem +15 -14
  555. data/test/rubygems/alternate_cert_32.pem +16 -15
  556. data/test/rubygems/alternate_key.pem +25 -25
  557. data/test/rubygems/bad_rake.rb +1 -0
  558. data/test/rubygems/bundler_test_gem.rb +424 -0
  559. data/test/rubygems/ca_cert.pem +74 -65
  560. data/test/rubygems/child_cert.pem +16 -15
  561. data/test/rubygems/child_cert_32.pem +16 -15
  562. data/test/rubygems/child_key.pem +25 -25
  563. data/test/rubygems/client.pem +103 -45
  564. data/test/rubygems/data/excon-0.7.7.gemspec.rz +0 -0
  565. data/test/rubygems/data/null-required-ruby-version.gemspec.rz +0 -0
  566. data/test/rubygems/data/null-required-rubygems-version.gemspec.rz +0 -0
  567. data/test/rubygems/data/pry-0.4.7.gemspec.rz +0 -0
  568. data/test/rubygems/encrypted_private_key.pem +26 -26
  569. data/test/rubygems/expired_cert.pem +15 -14
  570. data/test/rubygems/fake_certlib/openssl.rb +1 -0
  571. data/test/rubygems/future_cert.pem +15 -14
  572. data/test/rubygems/future_cert_32.pem +15 -14
  573. data/test/rubygems/good_rake.rb +1 -0
  574. data/test/rubygems/grandchild_cert.pem +16 -15
  575. data/test/rubygems/grandchild_cert_32.pem +16 -15
  576. data/test/rubygems/grandchild_key.pem +25 -25
  577. data/{lib/rubygems/test_case.rb → test/rubygems/helper.rb} +643 -490
  578. data/{lib → test}/rubygems/installer_test_case.rb +118 -64
  579. data/test/rubygems/invalid_issuer_cert.pem +17 -15
  580. data/test/rubygems/invalid_issuer_cert_32.pem +17 -15
  581. data/test/rubygems/invalid_key.pem +25 -25
  582. data/test/rubygems/invalid_signer_cert.pem +16 -15
  583. data/test/rubygems/invalid_signer_cert_32.pem +16 -15
  584. data/test/rubygems/invalidchild_cert.pem +16 -15
  585. data/test/rubygems/invalidchild_cert_32.pem +16 -15
  586. data/test/rubygems/invalidchild_key.pem +25 -25
  587. data/test/rubygems/multifactor_auth_utilities.rb +111 -0
  588. data/{lib → test}/rubygems/package/tar_test_case.rb +54 -26
  589. data/test/rubygems/packages/Bluebie-legs-0.6.2.gem +0 -0
  590. data/test/rubygems/packages/ascii_binder-0.1.10.1.gem +0 -0
  591. data/test/rubygems/packages/ill-formatted-platform-1.0.0.10.gem +0 -0
  592. data/test/rubygems/plugin/exception/rubygems_plugin.rb +2 -1
  593. data/test/rubygems/plugin/load/rubygems_plugin.rb +1 -0
  594. data/test/rubygems/plugin/standarderror/rubygems_plugin.rb +2 -1
  595. data/test/rubygems/private3072_key.pem +40 -0
  596. data/test/rubygems/private_ec_key.pem +9 -0
  597. data/test/rubygems/private_key.pem +25 -25
  598. data/test/rubygems/public3072_cert.pem +25 -0
  599. data/test/rubygems/public_cert.pem +17 -15
  600. data/test/rubygems/public_cert_32.pem +16 -15
  601. data/test/rubygems/public_key.pem +7 -7
  602. data/test/rubygems/rubygems/commands/crash_command.rb +1 -2
  603. data/test/rubygems/rubygems_plugin.rb +7 -5
  604. data/test/rubygems/simple_gem.rb +1 -0
  605. data/test/rubygems/specifications/bar-0.0.2.gemspec +1 -1
  606. data/test/rubygems/specifications/rubyforge-0.0.1.gemspec +14 -0
  607. data/test/rubygems/ssl_cert.pem +78 -17
  608. data/test/rubygems/ssl_key.pem +25 -13
  609. data/test/rubygems/test_bundled_ca.rb +45 -43
  610. data/test/rubygems/test_config.rb +13 -9
  611. data/test/rubygems/test_deprecate.rb +91 -10
  612. data/test/rubygems/test_exit.rb +17 -0
  613. data/test/rubygems/test_gem.rb +917 -797
  614. data/test/rubygems/test_gem_available_set.rb +25 -25
  615. data/test/rubygems/test_gem_bundler_version_finder.rb +127 -0
  616. data/test/rubygems/test_gem_command.rb +195 -40
  617. data/test/rubygems/test_gem_command_manager.rb +182 -46
  618. data/test/rubygems/test_gem_commands_build_command.rb +646 -28
  619. data/test/rubygems/test_gem_commands_cert_command.rb +321 -126
  620. data/test/rubygems/test_gem_commands_check_command.rb +11 -12
  621. data/test/rubygems/test_gem_commands_cleanup_command.rb +147 -52
  622. data/test/rubygems/test_gem_commands_contents_command.rb +75 -44
  623. data/test/rubygems/test_gem_commands_dependency_command.rb +61 -63
  624. data/test/rubygems/test_gem_commands_environment_command.rb +62 -47
  625. data/test/rubygems/test_gem_commands_exec_command.rb +857 -0
  626. data/test/rubygems/test_gem_commands_fetch_command.rb +164 -33
  627. data/test/rubygems/test_gem_commands_generate_index_command.rb +39 -9
  628. data/test/rubygems/test_gem_commands_help_command.rb +36 -17
  629. data/test/rubygems/test_gem_commands_info_command.rb +70 -0
  630. data/test/rubygems/test_gem_commands_install_command.rb +736 -150
  631. data/test/rubygems/test_gem_commands_list_command.rb +6 -7
  632. data/test/rubygems/test_gem_commands_lock_command.rb +12 -14
  633. data/test/rubygems/test_gem_commands_mirror.rb +4 -4
  634. data/test/rubygems/test_gem_commands_open_command.rb +47 -16
  635. data/test/rubygems/test_gem_commands_outdated_command.rb +25 -8
  636. data/test/rubygems/test_gem_commands_owner_command.rb +368 -70
  637. data/test/rubygems/test_gem_commands_pristine_command.rb +318 -101
  638. data/test/rubygems/test_gem_commands_push_command.rb +331 -58
  639. data/test/rubygems/test_gem_commands_query_command.rb +329 -128
  640. data/test/rubygems/test_gem_commands_search_command.rb +3 -5
  641. data/test/rubygems/test_gem_commands_server_command.rb +7 -47
  642. data/test/rubygems/test_gem_commands_setup_command.rb +404 -66
  643. data/test/rubygems/test_gem_commands_signin_command.rb +259 -0
  644. data/test/rubygems/test_gem_commands_signout_command.rb +30 -0
  645. data/test/rubygems/test_gem_commands_sources_command.rb +316 -31
  646. data/test/rubygems/test_gem_commands_specification_command.rb +82 -56
  647. data/test/rubygems/test_gem_commands_stale_command.rb +9 -9
  648. data/test/rubygems/test_gem_commands_uninstall_command.rb +347 -88
  649. data/test/rubygems/test_gem_commands_unpack_command.rb +49 -34
  650. data/test/rubygems/test_gem_commands_update_command.rb +429 -107
  651. data/test/rubygems/test_gem_commands_which_command.rb +13 -15
  652. data/test/rubygems/test_gem_commands_yank_command.rb +227 -28
  653. data/test/rubygems/test_gem_config_file.rb +168 -108
  654. data/test/rubygems/test_gem_dependency.rb +112 -76
  655. data/test/rubygems/test_gem_dependency_installer.rb +346 -391
  656. data/test/rubygems/test_gem_dependency_list.rb +68 -63
  657. data/test/rubygems/test_gem_dependency_resolution_error.rb +6 -8
  658. data/test/rubygems/test_gem_doctor.rb +75 -49
  659. data/test/rubygems/test_gem_ext_builder.rb +121 -125
  660. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/.gitignore +1 -0
  661. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/custom_name.gemspec +10 -0
  662. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.lock +249 -0
  663. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/Cargo.toml +10 -0
  664. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/ext/custom_name_lib/src/lib.rs +27 -0
  665. data/test/rubygems/test_gem_ext_cargo_builder/custom_name/lib/custom_name.rb +3 -0
  666. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/.gitignore +1 -0
  667. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.lock +249 -0
  668. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.toml +10 -0
  669. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/rust_ruby_example.gemspec +10 -0
  670. data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/src/lib.rs +51 -0
  671. data/test/rubygems/test_gem_ext_cargo_builder.rb +167 -0
  672. data/test/rubygems/test_gem_ext_cargo_builder_link_flag_converter.rb +34 -0
  673. data/test/rubygems/test_gem_ext_cargo_builder_unit.rb +60 -0
  674. data/test/rubygems/test_gem_ext_cmake_builder.rb +33 -36
  675. data/test/rubygems/test_gem_ext_configure_builder.rb +25 -32
  676. data/test/rubygems/test_gem_ext_ext_conf_builder.rb +94 -76
  677. data/test/rubygems/test_gem_ext_rake_builder.rb +79 -31
  678. data/test/rubygems/test_gem_gem_runner.rb +59 -9
  679. data/test/rubygems/test_gem_gemcutter_utilities.rb +210 -84
  680. data/test/rubygems/test_gem_impossible_dependencies_error.rb +5 -7
  681. data/test/rubygems/test_gem_indexer.rb +121 -107
  682. data/test/rubygems/test_gem_install_update_options.rb +65 -54
  683. data/test/rubygems/test_gem_installer.rb +1517 -557
  684. data/test/rubygems/test_gem_local_remote_options.rb +14 -15
  685. data/test/rubygems/test_gem_name_tuple.rb +5 -7
  686. data/test/rubygems/test_gem_package.rb +673 -243
  687. data/test/rubygems/test_gem_package_old.rb +58 -57
  688. data/test/rubygems/test_gem_package_tar_header.rb +129 -50
  689. data/test/rubygems/test_gem_package_tar_reader.rb +71 -11
  690. data/test/rubygems/test_gem_package_tar_reader_entry.rb +229 -21
  691. data/test/rubygems/test_gem_package_tar_writer.rb +168 -101
  692. data/test/rubygems/test_gem_package_task.rb +59 -25
  693. data/test/rubygems/test_gem_path_support.rb +49 -31
  694. data/test/rubygems/test_gem_platform.rb +393 -204
  695. data/test/rubygems/test_gem_rdoc.rb +23 -156
  696. data/test/rubygems/test_gem_remote_fetcher.rb +580 -404
  697. data/test/rubygems/test_gem_request.rb +270 -86
  698. data/test/rubygems/test_gem_request_connection_pools.rb +57 -35
  699. data/test/rubygems/test_gem_request_set.rb +192 -115
  700. data/test/rubygems/test_gem_request_set_gem_dependency_api.rb +300 -278
  701. data/test/rubygems/test_gem_request_set_lockfile.rb +95 -96
  702. data/test/rubygems/test_gem_request_set_lockfile_parser.rb +73 -78
  703. data/test/rubygems/test_gem_request_set_lockfile_tokenizer.rb +138 -137
  704. data/test/rubygems/test_gem_requirement.rb +175 -57
  705. data/test/rubygems/test_gem_resolver.rb +257 -113
  706. data/test/rubygems/test_gem_resolver_activation_request.rb +10 -41
  707. data/test/rubygems/test_gem_resolver_api_set.rb +80 -79
  708. data/test/rubygems/test_gem_resolver_api_specification.rb +64 -42
  709. data/test/rubygems/test_gem_resolver_best_set.rb +44 -23
  710. data/test/rubygems/test_gem_resolver_composed_set.rb +2 -4
  711. data/test/rubygems/test_gem_resolver_conflict.rb +13 -19
  712. data/test/rubygems/test_gem_resolver_dependency_request.rb +16 -18
  713. data/test/rubygems/test_gem_resolver_git_set.rb +23 -25
  714. data/test/rubygems/test_gem_resolver_git_specification.rb +23 -23
  715. data/test/rubygems/test_gem_resolver_index_set.rb +15 -17
  716. data/test/rubygems/test_gem_resolver_index_specification.rb +22 -19
  717. data/test/rubygems/test_gem_resolver_installed_specification.rb +6 -9
  718. data/test/rubygems/test_gem_resolver_installer_set.rb +110 -48
  719. data/test/rubygems/test_gem_resolver_local_specification.rb +8 -10
  720. data/test/rubygems/test_gem_resolver_lock_set.rb +16 -18
  721. data/test/rubygems/test_gem_resolver_lock_specification.rb +18 -20
  722. data/test/rubygems/test_gem_resolver_requirement_list.rb +2 -4
  723. data/test/rubygems/test_gem_resolver_specification.rb +10 -12
  724. data/test/rubygems/test_gem_resolver_vendor_set.rb +10 -12
  725. data/test/rubygems/test_gem_resolver_vendor_specification.rb +11 -13
  726. data/test/rubygems/test_gem_security.rb +116 -82
  727. data/test/rubygems/test_gem_security_policy.rb +128 -134
  728. data/test/rubygems/test_gem_security_signer.rb +58 -49
  729. data/test/rubygems/test_gem_security_trust_dir.rb +19 -21
  730. data/test/rubygems/test_gem_silent_ui.rb +48 -42
  731. data/test/rubygems/test_gem_source.rb +73 -61
  732. data/test/rubygems/test_gem_source_fetch_problem.rb +23 -6
  733. data/test/rubygems/test_gem_source_git.rb +79 -78
  734. data/test/rubygems/test_gem_source_installed.rb +17 -19
  735. data/test/rubygems/test_gem_source_list.rb +6 -5
  736. data/test/rubygems/test_gem_source_local.rb +16 -16
  737. data/test/rubygems/test_gem_source_lock.rb +32 -34
  738. data/test/rubygems/test_gem_source_specific_file.rb +19 -19
  739. data/test/rubygems/test_gem_source_subpath_problem.rb +50 -0
  740. data/test/rubygems/test_gem_source_vendor.rb +14 -16
  741. data/test/rubygems/test_gem_spec_fetcher.rb +89 -62
  742. data/test/rubygems/test_gem_specification.rb +1441 -1104
  743. data/test/rubygems/test_gem_stream_ui.rb +71 -55
  744. data/test/rubygems/test_gem_stub_specification.rb +102 -41
  745. data/test/rubygems/test_gem_text.rb +27 -1
  746. data/test/rubygems/test_gem_uninstaller.rb +289 -99
  747. data/test/rubygems/test_gem_unsatisfiable_dependency_error.rb +4 -6
  748. data/test/rubygems/test_gem_update_suggestion.rb +209 -0
  749. data/test/rubygems/test_gem_uri.rb +41 -0
  750. data/test/rubygems/test_gem_uri_formatter.rb +15 -17
  751. data/test/rubygems/test_gem_util.rb +68 -17
  752. data/test/rubygems/test_gem_validator.rb +12 -16
  753. data/test/rubygems/test_gem_version.rb +123 -40
  754. data/test/rubygems/test_gem_version_option.rb +30 -17
  755. data/test/rubygems/test_kernel.rb +75 -37
  756. data/test/rubygems/test_project_sanity.rb +49 -0
  757. data/test/rubygems/test_remote_fetch_error.rb +20 -0
  758. data/test/rubygems/test_require.rb +527 -117
  759. data/test/rubygems/test_rubygems.rb +76 -0
  760. data/test/rubygems/test_webauthn_listener.rb +143 -0
  761. data/test/rubygems/test_webauthn_listener_response.rb +93 -0
  762. data/test/rubygems/test_webauthn_poller.rb +124 -0
  763. data/{lib/rubygems/test_utilities.rb → test/rubygems/utilities.rb} +135 -83
  764. data/test/rubygems/wrong_key_cert.pem +16 -15
  765. data/test/rubygems/wrong_key_cert_32.pem +16 -15
  766. data/test/test_changelog_generator.rb +17 -0
  767. metadata +513 -189
  768. data/.autotest +0 -71
  769. data/.document +0 -5
  770. data/.travis.yml +0 -46
  771. data/CONTRIBUTING.rdoc +0 -129
  772. data/CVE-2013-4287.txt +0 -35
  773. data/CVE-2013-4363.txt +0 -45
  774. data/CVE-2015-3900.txt +0 -40
  775. data/History.txt +0 -3094
  776. data/MAINTAINERS.md +0 -5
  777. data/POLICIES.rdoc +0 -61
  778. data/README.rdoc +0 -54
  779. data/Rakefile +0 -449
  780. data/UPGRADING.rdoc +0 -92
  781. data/appveyor.yml +0 -36
  782. data/bin/gem +0 -25
  783. data/bin/update_rubygems +0 -37
  784. data/lib/gauntlet_rubygems.rb +0 -51
  785. data/lib/rubygems/psych_additions.rb +0 -10
  786. data/lib/rubygems/server.rb +0 -869
  787. data/lib/rubygems/source_local.rb +0 -6
  788. data/lib/rubygems/source_specific_file.rb +0 -5
  789. data/lib/rubygems/ssl_certs/AddTrustExternalCARoot-2048.pem +0 -25
  790. data/lib/rubygems/ssl_certs/AddTrustExternalCARoot.pem +0 -32
  791. data/lib/rubygems/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem +0 -14
  792. data/lib/rubygems/ssl_certs/DigiCertHighAssuranceEVRootCA.pem +0 -23
  793. data/lib/rubygems/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem +0 -28
  794. data/lib/rubygems/ssl_certs/GeoTrustGlobalCA.pem +0 -20
  795. data/lib/rubygems/syck_hack.rb +0 -77
  796. data/lib/ubygems.rb +0 -11
  797. data/test/rubygems/data/null-type.gemspec.rz +0 -0
  798. data/test/rubygems/fix_openssl_warnings.rb +0 -13
  799. data/test/rubygems/test_gem_server.rb +0 -409
  800. data/util/CL2notes +0 -56
  801. data/util/create_certs.rb +0 -157
  802. data/util/create_encrypted_key.rb +0 -17
  803. data/util/generate_spdx_license_list.rb +0 -51
  804. data/util/update_bundled_ca_certificates.rb +0 -118
@@ -0,0 +1,2706 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'rbconfig'
5
+ rescue LoadError
6
+ # for make rjit-headers
7
+ end
8
+
9
+ # Namespace for file utility methods for copying, moving, removing, etc.
10
+ #
11
+ # == What's Here
12
+ #
13
+ # First, what’s elsewhere. \Module \Bundler::FileUtils:
14
+ #
15
+ # - Inherits from {class Object}[https://docs.ruby-lang.org/en/master/Object.html].
16
+ # - Supplements {class File}[https://docs.ruby-lang.org/en/master/File.html]
17
+ # (but is not included or extended there).
18
+ #
19
+ # Here, module \Bundler::FileUtils provides methods that are useful for:
20
+ #
21
+ # - {Creating}[rdoc-ref:FileUtils@Creating].
22
+ # - {Deleting}[rdoc-ref:FileUtils@Deleting].
23
+ # - {Querying}[rdoc-ref:FileUtils@Querying].
24
+ # - {Setting}[rdoc-ref:FileUtils@Setting].
25
+ # - {Comparing}[rdoc-ref:FileUtils@Comparing].
26
+ # - {Copying}[rdoc-ref:FileUtils@Copying].
27
+ # - {Moving}[rdoc-ref:FileUtils@Moving].
28
+ # - {Options}[rdoc-ref:FileUtils@Options].
29
+ #
30
+ # === Creating
31
+ #
32
+ # - ::mkdir: Creates directories.
33
+ # - ::mkdir_p, ::makedirs, ::mkpath: Creates directories,
34
+ # also creating ancestor directories as needed.
35
+ # - ::link_entry: Creates a hard link.
36
+ # - ::ln, ::link: Creates hard links.
37
+ # - ::ln_s, ::symlink: Creates symbolic links.
38
+ # - ::ln_sf: Creates symbolic links, overwriting if necessary.
39
+ # - ::ln_sr: Creates symbolic links relative to targets
40
+ #
41
+ # === Deleting
42
+ #
43
+ # - ::remove_dir: Removes a directory and its descendants.
44
+ # - ::remove_entry: Removes an entry, including its descendants if it is a directory.
45
+ # - ::remove_entry_secure: Like ::remove_entry, but removes securely.
46
+ # - ::remove_file: Removes a file entry.
47
+ # - ::rm, ::remove: Removes entries.
48
+ # - ::rm_f, ::safe_unlink: Like ::rm, but removes forcibly.
49
+ # - ::rm_r: Removes entries and their descendants.
50
+ # - ::rm_rf, ::rmtree: Like ::rm_r, but removes forcibly.
51
+ # - ::rmdir: Removes directories.
52
+ #
53
+ # === Querying
54
+ #
55
+ # - ::pwd, ::getwd: Returns the path to the working directory.
56
+ # - ::uptodate?: Returns whether a given entry is newer than given other entries.
57
+ #
58
+ # === Setting
59
+ #
60
+ # - ::cd, ::chdir: Sets the working directory.
61
+ # - ::chmod: Sets permissions for an entry.
62
+ # - ::chmod_R: Sets permissions for an entry and its descendants.
63
+ # - ::chown: Sets the owner and group for entries.
64
+ # - ::chown_R: Sets the owner and group for entries and their descendants.
65
+ # - ::touch: Sets modification and access times for entries,
66
+ # creating if necessary.
67
+ #
68
+ # === Comparing
69
+ #
70
+ # - ::compare_file, ::cmp, ::identical?: Returns whether two entries are identical.
71
+ # - ::compare_stream: Returns whether two streams are identical.
72
+ #
73
+ # === Copying
74
+ #
75
+ # - ::copy_entry: Recursively copies an entry.
76
+ # - ::copy_file: Copies an entry.
77
+ # - ::copy_stream: Copies a stream.
78
+ # - ::cp, ::copy: Copies files.
79
+ # - ::cp_lr: Recursively creates hard links.
80
+ # - ::cp_r: Recursively copies files, retaining mode, owner, and group.
81
+ # - ::install: Recursively copies files, optionally setting mode,
82
+ # owner, and group.
83
+ #
84
+ # === Moving
85
+ #
86
+ # - ::mv, ::move: Moves entries.
87
+ #
88
+ # === Options
89
+ #
90
+ # - ::collect_method: Returns the names of methods that accept a given option.
91
+ # - ::commands: Returns the names of methods that accept options.
92
+ # - ::have_option?: Returns whether a given method accepts a given option.
93
+ # - ::options: Returns all option names.
94
+ # - ::options_of: Returns the names of the options for a given method.
95
+ #
96
+ # == Path Arguments
97
+ #
98
+ # Some methods in \Bundler::FileUtils accept _path_ arguments,
99
+ # which are interpreted as paths to filesystem entries:
100
+ #
101
+ # - If the argument is a string, that value is the path.
102
+ # - If the argument has method +:to_path+, it is converted via that method.
103
+ # - If the argument has method +:to_str+, it is converted via that method.
104
+ #
105
+ # == About the Examples
106
+ #
107
+ # Some examples here involve trees of file entries.
108
+ # For these, we sometimes display trees using the
109
+ # {tree command-line utility}[https://en.wikipedia.org/wiki/Tree_(command)],
110
+ # which is a recursive directory-listing utility that produces
111
+ # a depth-indented listing of files and directories.
112
+ #
113
+ # We use a helper method to launch the command and control the format:
114
+ #
115
+ # def tree(dirpath = '.')
116
+ # command = "tree --noreport --charset=ascii #{dirpath}"
117
+ # system(command)
118
+ # end
119
+ #
120
+ # To illustrate:
121
+ #
122
+ # tree('src0')
123
+ # # => src0
124
+ # # |-- sub0
125
+ # # | |-- src0.txt
126
+ # # | `-- src1.txt
127
+ # # `-- sub1
128
+ # # |-- src2.txt
129
+ # # `-- src3.txt
130
+ #
131
+ # == Avoiding the TOCTTOU Vulnerability
132
+ #
133
+ # For certain methods that recursively remove entries,
134
+ # there is a potential vulnerability called the
135
+ # {Time-of-check to time-of-use}[https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use],
136
+ # or TOCTTOU, vulnerability that can exist when:
137
+ #
138
+ # - An ancestor directory of the entry at the target path is world writable;
139
+ # such directories include <tt>/tmp</tt>.
140
+ # - The directory tree at the target path includes:
141
+ #
142
+ # - A world-writable descendant directory.
143
+ # - A symbolic link.
144
+ #
145
+ # To avoid that vulnerability, you can use this method to remove entries:
146
+ #
147
+ # - Bundler::FileUtils.remove_entry_secure: removes recursively
148
+ # if the target path points to a directory.
149
+ #
150
+ # Also available are these methods,
151
+ # each of which calls \Bundler::FileUtils.remove_entry_secure:
152
+ #
153
+ # - Bundler::FileUtils.rm_r with keyword argument <tt>secure: true</tt>.
154
+ # - Bundler::FileUtils.rm_rf with keyword argument <tt>secure: true</tt>.
155
+ #
156
+ # Finally, this method for moving entries calls \Bundler::FileUtils.remove_entry_secure
157
+ # if the source and destination are on different file systems
158
+ # (which means that the "move" is really a copy and remove):
159
+ #
160
+ # - Bundler::FileUtils.mv with keyword argument <tt>secure: true</tt>.
161
+ #
162
+ # \Method \Bundler::FileUtils.remove_entry_secure removes securely
163
+ # by applying a special pre-process:
164
+ #
165
+ # - If the target path points to a directory, this method uses methods
166
+ # {File#chown}[https://docs.ruby-lang.org/en/master/File.html#method-i-chown]
167
+ # and {File#chmod}[https://docs.ruby-lang.org/en/master/File.html#method-i-chmod]
168
+ # in removing directories.
169
+ # - The owner of the target directory should be either the current process
170
+ # or the super user (root).
171
+ #
172
+ # WARNING: You must ensure that *ALL* parent directories cannot be
173
+ # moved by other untrusted users. For example, parent directories
174
+ # should not be owned by untrusted users, and should not be world
175
+ # writable except when the sticky bit is set.
176
+ #
177
+ # For details of this security vulnerability, see Perl cases:
178
+ #
179
+ # - {CVE-2005-0448}[https://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2005-0448].
180
+ # - {CVE-2004-0452}[https://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2004-0452].
181
+ #
182
+ module Bundler::FileUtils
183
+ VERSION = "1.7.0"
184
+
185
+ def self.private_module_function(name) #:nodoc:
186
+ module_function name
187
+ private_class_method name
188
+ end
189
+
190
+ #
191
+ # Returns a string containing the path to the current directory:
192
+ #
193
+ # Bundler::FileUtils.pwd # => "/rdoc/fileutils"
194
+ #
195
+ # Bundler::FileUtils.getwd is an alias for Bundler::FileUtils.pwd.
196
+ #
197
+ # Related: Bundler::FileUtils.cd.
198
+ #
199
+ def pwd
200
+ Dir.pwd
201
+ end
202
+ module_function :pwd
203
+
204
+ alias getwd pwd
205
+ module_function :getwd
206
+
207
+ # Changes the working directory to the given +dir+, which
208
+ # should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments]:
209
+ #
210
+ # With no block given,
211
+ # changes the current directory to the directory at +dir+; returns zero:
212
+ #
213
+ # Bundler::FileUtils.pwd # => "/rdoc/fileutils"
214
+ # Bundler::FileUtils.cd('..')
215
+ # Bundler::FileUtils.pwd # => "/rdoc"
216
+ # Bundler::FileUtils.cd('fileutils')
217
+ #
218
+ # With a block given, changes the current directory to the directory
219
+ # at +dir+, calls the block with argument +dir+,
220
+ # and restores the original current directory; returns the block's value:
221
+ #
222
+ # Bundler::FileUtils.pwd # => "/rdoc/fileutils"
223
+ # Bundler::FileUtils.cd('..') { |arg| [arg, Bundler::FileUtils.pwd] } # => ["..", "/rdoc"]
224
+ # Bundler::FileUtils.pwd # => "/rdoc/fileutils"
225
+ #
226
+ # Keyword arguments:
227
+ #
228
+ # - <tt>verbose: true</tt> - prints an equivalent command:
229
+ #
230
+ # Bundler::FileUtils.cd('..')
231
+ # Bundler::FileUtils.cd('fileutils')
232
+ #
233
+ # Output:
234
+ #
235
+ # cd ..
236
+ # cd fileutils
237
+ #
238
+ # Bundler::FileUtils.chdir is an alias for Bundler::FileUtils.cd.
239
+ #
240
+ # Related: Bundler::FileUtils.pwd.
241
+ #
242
+ def cd(dir, verbose: nil, &block) # :yield: dir
243
+ fu_output_message "cd #{dir}" if verbose
244
+ result = Dir.chdir(dir, &block)
245
+ fu_output_message 'cd -' if verbose and block
246
+ result
247
+ end
248
+ module_function :cd
249
+
250
+ alias chdir cd
251
+ module_function :chdir
252
+
253
+ #
254
+ # Returns +true+ if the file at path +new+
255
+ # is newer than all the files at paths in array +old_list+;
256
+ # +false+ otherwise.
257
+ #
258
+ # Argument +new+ and the elements of +old_list+
259
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments]:
260
+ #
261
+ # Bundler::FileUtils.uptodate?('Rakefile', ['Gemfile', 'README.md']) # => true
262
+ # Bundler::FileUtils.uptodate?('Gemfile', ['Rakefile', 'README.md']) # => false
263
+ #
264
+ # A non-existent file is considered to be infinitely old.
265
+ #
266
+ # Related: Bundler::FileUtils.touch.
267
+ #
268
+ def uptodate?(new, old_list)
269
+ return false unless File.exist?(new)
270
+ new_time = File.mtime(new)
271
+ old_list.each do |old|
272
+ if File.exist?(old)
273
+ return false unless new_time > File.mtime(old)
274
+ end
275
+ end
276
+ true
277
+ end
278
+ module_function :uptodate?
279
+
280
+ def remove_trailing_slash(dir) #:nodoc:
281
+ dir == '/' ? dir : dir.chomp(?/)
282
+ end
283
+ private_module_function :remove_trailing_slash
284
+
285
+ #
286
+ # Creates directories at the paths in the given +list+
287
+ # (a single path or an array of paths);
288
+ # returns +list+ if it is an array, <tt>[list]</tt> otherwise.
289
+ #
290
+ # Argument +list+ or its elements
291
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
292
+ #
293
+ # With no keyword arguments, creates a directory at each +path+ in +list+
294
+ # by calling: <tt>Dir.mkdir(path, mode)</tt>;
295
+ # see {Dir.mkdir}[https://docs.ruby-lang.org/en/master/Dir.html#method-c-mkdir]:
296
+ #
297
+ # Bundler::FileUtils.mkdir(%w[tmp0 tmp1]) # => ["tmp0", "tmp1"]
298
+ # Bundler::FileUtils.mkdir('tmp4') # => ["tmp4"]
299
+ #
300
+ # Keyword arguments:
301
+ #
302
+ # - <tt>mode: <i>mode</i></tt> - also calls <tt>File.chmod(mode, path)</tt>;
303
+ # see {File.chmod}[https://docs.ruby-lang.org/en/master/File.html#method-c-chmod].
304
+ # - <tt>noop: true</tt> - does not create directories.
305
+ # - <tt>verbose: true</tt> - prints an equivalent command:
306
+ #
307
+ # Bundler::FileUtils.mkdir(%w[tmp0 tmp1], verbose: true)
308
+ # Bundler::FileUtils.mkdir(%w[tmp2 tmp3], mode: 0700, verbose: true)
309
+ #
310
+ # Output:
311
+ #
312
+ # mkdir tmp0 tmp1
313
+ # mkdir -m 700 tmp2 tmp3
314
+ #
315
+ # Raises an exception if any path points to an existing
316
+ # file or directory, or if for any reason a directory cannot be created.
317
+ #
318
+ # Related: Bundler::FileUtils.mkdir_p.
319
+ #
320
+ def mkdir(list, mode: nil, noop: nil, verbose: nil)
321
+ list = fu_list(list)
322
+ fu_output_message "mkdir #{mode ? ('-m %03o ' % mode) : ''}#{list.join ' '}" if verbose
323
+ return if noop
324
+
325
+ list.each do |dir|
326
+ fu_mkdir dir, mode
327
+ end
328
+ end
329
+ module_function :mkdir
330
+
331
+ #
332
+ # Creates directories at the paths in the given +list+
333
+ # (a single path or an array of paths),
334
+ # also creating ancestor directories as needed;
335
+ # returns +list+ if it is an array, <tt>[list]</tt> otherwise.
336
+ #
337
+ # Argument +list+ or its elements
338
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
339
+ #
340
+ # With no keyword arguments, creates a directory at each +path+ in +list+,
341
+ # along with any needed ancestor directories,
342
+ # by calling: <tt>Dir.mkdir(path, mode)</tt>;
343
+ # see {Dir.mkdir}[https://docs.ruby-lang.org/en/master/Dir.html#method-c-mkdir]:
344
+ #
345
+ # Bundler::FileUtils.mkdir_p(%w[tmp0/tmp1 tmp2/tmp3]) # => ["tmp0/tmp1", "tmp2/tmp3"]
346
+ # Bundler::FileUtils.mkdir_p('tmp4/tmp5') # => ["tmp4/tmp5"]
347
+ #
348
+ # Keyword arguments:
349
+ #
350
+ # - <tt>mode: <i>mode</i></tt> - also calls <tt>File.chmod(mode, path)</tt>;
351
+ # see {File.chmod}[https://docs.ruby-lang.org/en/master/File.html#method-c-chmod].
352
+ # - <tt>noop: true</tt> - does not create directories.
353
+ # - <tt>verbose: true</tt> - prints an equivalent command:
354
+ #
355
+ # Bundler::FileUtils.mkdir_p(%w[tmp0 tmp1], verbose: true)
356
+ # Bundler::FileUtils.mkdir_p(%w[tmp2 tmp3], mode: 0700, verbose: true)
357
+ #
358
+ # Output:
359
+ #
360
+ # mkdir -p tmp0 tmp1
361
+ # mkdir -p -m 700 tmp2 tmp3
362
+ #
363
+ # Raises an exception if for any reason a directory cannot be created.
364
+ #
365
+ # Bundler::FileUtils.mkpath and Bundler::FileUtils.makedirs are aliases for Bundler::FileUtils.mkdir_p.
366
+ #
367
+ # Related: Bundler::FileUtils.mkdir.
368
+ #
369
+ def mkdir_p(list, mode: nil, noop: nil, verbose: nil)
370
+ list = fu_list(list)
371
+ fu_output_message "mkdir -p #{mode ? ('-m %03o ' % mode) : ''}#{list.join ' '}" if verbose
372
+ return *list if noop
373
+
374
+ list.each do |item|
375
+ path = remove_trailing_slash(item)
376
+
377
+ stack = []
378
+ until File.directory?(path) || File.dirname(path) == path
379
+ stack.push path
380
+ path = File.dirname(path)
381
+ end
382
+ stack.reverse_each do |dir|
383
+ begin
384
+ fu_mkdir dir, mode
385
+ rescue SystemCallError
386
+ raise unless File.directory?(dir)
387
+ end
388
+ end
389
+ end
390
+
391
+ return *list
392
+ end
393
+ module_function :mkdir_p
394
+
395
+ alias mkpath mkdir_p
396
+ alias makedirs mkdir_p
397
+ module_function :mkpath
398
+ module_function :makedirs
399
+
400
+ def fu_mkdir(path, mode) #:nodoc:
401
+ path = remove_trailing_slash(path)
402
+ if mode
403
+ Dir.mkdir path, mode
404
+ File.chmod mode, path
405
+ else
406
+ Dir.mkdir path
407
+ end
408
+ end
409
+ private_module_function :fu_mkdir
410
+
411
+ #
412
+ # Removes directories at the paths in the given +list+
413
+ # (a single path or an array of paths);
414
+ # returns +list+, if it is an array, <tt>[list]</tt> otherwise.
415
+ #
416
+ # Argument +list+ or its elements
417
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
418
+ #
419
+ # With no keyword arguments, removes the directory at each +path+ in +list+,
420
+ # by calling: <tt>Dir.rmdir(path)</tt>;
421
+ # see {Dir.rmdir}[https://docs.ruby-lang.org/en/master/Dir.html#method-c-rmdir]:
422
+ #
423
+ # Bundler::FileUtils.rmdir(%w[tmp0/tmp1 tmp2/tmp3]) # => ["tmp0/tmp1", "tmp2/tmp3"]
424
+ # Bundler::FileUtils.rmdir('tmp4/tmp5') # => ["tmp4/tmp5"]
425
+ #
426
+ # Keyword arguments:
427
+ #
428
+ # - <tt>parents: true</tt> - removes successive ancestor directories
429
+ # if empty.
430
+ # - <tt>noop: true</tt> - does not remove directories.
431
+ # - <tt>verbose: true</tt> - prints an equivalent command:
432
+ #
433
+ # Bundler::FileUtils.rmdir(%w[tmp0/tmp1 tmp2/tmp3], parents: true, verbose: true)
434
+ # Bundler::FileUtils.rmdir('tmp4/tmp5', parents: true, verbose: true)
435
+ #
436
+ # Output:
437
+ #
438
+ # rmdir -p tmp0/tmp1 tmp2/tmp3
439
+ # rmdir -p tmp4/tmp5
440
+ #
441
+ # Raises an exception if a directory does not exist
442
+ # or if for any reason a directory cannot be removed.
443
+ #
444
+ # Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
445
+ #
446
+ def rmdir(list, parents: nil, noop: nil, verbose: nil)
447
+ list = fu_list(list)
448
+ fu_output_message "rmdir #{parents ? '-p ' : ''}#{list.join ' '}" if verbose
449
+ return if noop
450
+ list.each do |dir|
451
+ Dir.rmdir(dir = remove_trailing_slash(dir))
452
+ if parents
453
+ begin
454
+ until (parent = File.dirname(dir)) == '.' or parent == dir
455
+ dir = parent
456
+ Dir.rmdir(dir)
457
+ end
458
+ rescue Errno::ENOTEMPTY, Errno::EEXIST, Errno::ENOENT
459
+ end
460
+ end
461
+ end
462
+ end
463
+ module_function :rmdir
464
+
465
+ # Creates {hard links}[https://en.wikipedia.org/wiki/Hard_link].
466
+ #
467
+ # Arguments +src+ (a single path or an array of paths)
468
+ # and +dest+ (a single path)
469
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
470
+ #
471
+ # When +src+ is the path to an existing file
472
+ # and +dest+ is the path to a non-existent file,
473
+ # creates a hard link at +dest+ pointing to +src+; returns zero:
474
+ #
475
+ # Dir.children('tmp0/') # => ["t.txt"]
476
+ # Dir.children('tmp1/') # => []
477
+ # Bundler::FileUtils.ln('tmp0/t.txt', 'tmp1/t.lnk') # => 0
478
+ # Dir.children('tmp1/') # => ["t.lnk"]
479
+ #
480
+ # When +src+ is the path to an existing file
481
+ # and +dest+ is the path to an existing directory,
482
+ # creates a hard link at <tt>dest/src</tt> pointing to +src+; returns zero:
483
+ #
484
+ # Dir.children('tmp2') # => ["t.dat"]
485
+ # Dir.children('tmp3') # => []
486
+ # Bundler::FileUtils.ln('tmp2/t.dat', 'tmp3') # => 0
487
+ # Dir.children('tmp3') # => ["t.dat"]
488
+ #
489
+ # When +src+ is an array of paths to existing files
490
+ # and +dest+ is the path to an existing directory,
491
+ # then for each path +target+ in +src+,
492
+ # creates a hard link at <tt>dest/target</tt> pointing to +target+;
493
+ # returns +src+:
494
+ #
495
+ # Dir.children('tmp4/') # => []
496
+ # Bundler::FileUtils.ln(['tmp0/t.txt', 'tmp2/t.dat'], 'tmp4/') # => ["tmp0/t.txt", "tmp2/t.dat"]
497
+ # Dir.children('tmp4/') # => ["t.dat", "t.txt"]
498
+ #
499
+ # Keyword arguments:
500
+ #
501
+ # - <tt>force: true</tt> - overwrites +dest+ if it exists.
502
+ # - <tt>noop: true</tt> - does not create links.
503
+ # - <tt>verbose: true</tt> - prints an equivalent command:
504
+ #
505
+ # Bundler::FileUtils.ln('tmp0/t.txt', 'tmp1/t.lnk', verbose: true)
506
+ # Bundler::FileUtils.ln('tmp2/t.dat', 'tmp3', verbose: true)
507
+ # Bundler::FileUtils.ln(['tmp0/t.txt', 'tmp2/t.dat'], 'tmp4/', verbose: true)
508
+ #
509
+ # Output:
510
+ #
511
+ # ln tmp0/t.txt tmp1/t.lnk
512
+ # ln tmp2/t.dat tmp3
513
+ # ln tmp0/t.txt tmp2/t.dat tmp4/
514
+ #
515
+ # Raises an exception if +dest+ is the path to an existing file
516
+ # and keyword argument +force+ is not +true+.
517
+ #
518
+ # Bundler::FileUtils#link is an alias for Bundler::FileUtils#ln.
519
+ #
520
+ # Related: Bundler::FileUtils.link_entry (has different options).
521
+ #
522
+ def ln(src, dest, force: nil, noop: nil, verbose: nil)
523
+ fu_output_message "ln#{force ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if verbose
524
+ return if noop
525
+ fu_each_src_dest0(src, dest) do |s,d|
526
+ remove_file d, true if force
527
+ File.link s, d
528
+ end
529
+ end
530
+ module_function :ln
531
+
532
+ alias link ln
533
+ module_function :link
534
+
535
+ # Creates {hard links}[https://en.wikipedia.org/wiki/Hard_link].
536
+ #
537
+ # Arguments +src+ (a single path or an array of paths)
538
+ # and +dest+ (a single path)
539
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
540
+ #
541
+ # If +src+ is the path to a directory and +dest+ does not exist,
542
+ # creates links +dest+ and descendents pointing to +src+ and its descendents:
543
+ #
544
+ # tree('src0')
545
+ # # => src0
546
+ # # |-- sub0
547
+ # # | |-- src0.txt
548
+ # # | `-- src1.txt
549
+ # # `-- sub1
550
+ # # |-- src2.txt
551
+ # # `-- src3.txt
552
+ # File.exist?('dest0') # => false
553
+ # Bundler::FileUtils.cp_lr('src0', 'dest0')
554
+ # tree('dest0')
555
+ # # => dest0
556
+ # # |-- sub0
557
+ # # | |-- src0.txt
558
+ # # | `-- src1.txt
559
+ # # `-- sub1
560
+ # # |-- src2.txt
561
+ # # `-- src3.txt
562
+ #
563
+ # If +src+ and +dest+ are both paths to directories,
564
+ # creates links <tt>dest/src</tt> and descendents
565
+ # pointing to +src+ and its descendents:
566
+ #
567
+ # tree('src1')
568
+ # # => src1
569
+ # # |-- sub0
570
+ # # | |-- src0.txt
571
+ # # | `-- src1.txt
572
+ # # `-- sub1
573
+ # # |-- src2.txt
574
+ # # `-- src3.txt
575
+ # Bundler::FileUtils.mkdir('dest1')
576
+ # Bundler::FileUtils.cp_lr('src1', 'dest1')
577
+ # tree('dest1')
578
+ # # => dest1
579
+ # # `-- src1
580
+ # # |-- sub0
581
+ # # | |-- src0.txt
582
+ # # | `-- src1.txt
583
+ # # `-- sub1
584
+ # # |-- src2.txt
585
+ # # `-- src3.txt
586
+ #
587
+ # If +src+ is an array of paths to entries and +dest+ is the path to a directory,
588
+ # for each path +filepath+ in +src+, creates a link at <tt>dest/filepath</tt>
589
+ # pointing to that path:
590
+ #
591
+ # tree('src2')
592
+ # # => src2
593
+ # # |-- sub0
594
+ # # | |-- src0.txt
595
+ # # | `-- src1.txt
596
+ # # `-- sub1
597
+ # # |-- src2.txt
598
+ # # `-- src3.txt
599
+ # Bundler::FileUtils.mkdir('dest2')
600
+ # Bundler::FileUtils.cp_lr(['src2/sub0', 'src2/sub1'], 'dest2')
601
+ # tree('dest2')
602
+ # # => dest2
603
+ # # |-- sub0
604
+ # # | |-- src0.txt
605
+ # # | `-- src1.txt
606
+ # # `-- sub1
607
+ # # |-- src2.txt
608
+ # # `-- src3.txt
609
+ #
610
+ # Keyword arguments:
611
+ #
612
+ # - <tt>dereference_root: false</tt> - if +src+ is a symbolic link,
613
+ # does not dereference it.
614
+ # - <tt>noop: true</tt> - does not create links.
615
+ # - <tt>remove_destination: true</tt> - removes +dest+ before creating links.
616
+ # - <tt>verbose: true</tt> - prints an equivalent command:
617
+ #
618
+ # Bundler::FileUtils.cp_lr('src0', 'dest0', noop: true, verbose: true)
619
+ # Bundler::FileUtils.cp_lr('src1', 'dest1', noop: true, verbose: true)
620
+ # Bundler::FileUtils.cp_lr(['src2/sub0', 'src2/sub1'], 'dest2', noop: true, verbose: true)
621
+ #
622
+ # Output:
623
+ #
624
+ # cp -lr src0 dest0
625
+ # cp -lr src1 dest1
626
+ # cp -lr src2/sub0 src2/sub1 dest2
627
+ #
628
+ # Raises an exception if +dest+ is the path to an existing file or directory
629
+ # and keyword argument <tt>remove_destination: true</tt> is not given.
630
+ #
631
+ # Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
632
+ #
633
+ def cp_lr(src, dest, noop: nil, verbose: nil,
634
+ dereference_root: true, remove_destination: false)
635
+ fu_output_message "cp -lr#{remove_destination ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if verbose
636
+ return if noop
637
+ fu_each_src_dest(src, dest) do |s, d|
638
+ link_entry s, d, dereference_root, remove_destination
639
+ end
640
+ end
641
+ module_function :cp_lr
642
+
643
+ # Creates {symbolic links}[https://en.wikipedia.org/wiki/Symbolic_link].
644
+ #
645
+ # Arguments +src+ (a single path or an array of paths)
646
+ # and +dest+ (a single path)
647
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
648
+ #
649
+ # If +src+ is the path to an existing file:
650
+ #
651
+ # - When +dest+ is the path to a non-existent file,
652
+ # creates a symbolic link at +dest+ pointing to +src+:
653
+ #
654
+ # Bundler::FileUtils.touch('src0.txt')
655
+ # File.exist?('dest0.txt') # => false
656
+ # Bundler::FileUtils.ln_s('src0.txt', 'dest0.txt')
657
+ # File.symlink?('dest0.txt') # => true
658
+ #
659
+ # - When +dest+ is the path to an existing file,
660
+ # creates a symbolic link at +dest+ pointing to +src+
661
+ # if and only if keyword argument <tt>force: true</tt> is given
662
+ # (raises an exception otherwise):
663
+ #
664
+ # Bundler::FileUtils.touch('src1.txt')
665
+ # Bundler::FileUtils.touch('dest1.txt')
666
+ # Bundler::FileUtils.ln_s('src1.txt', 'dest1.txt', force: true)
667
+ # FileTest.symlink?('dest1.txt') # => true
668
+ #
669
+ # Bundler::FileUtils.ln_s('src1.txt', 'dest1.txt') # Raises Errno::EEXIST.
670
+ #
671
+ # If +dest+ is the path to a directory,
672
+ # creates a symbolic link at <tt>dest/src</tt> pointing to +src+:
673
+ #
674
+ # Bundler::FileUtils.touch('src2.txt')
675
+ # Bundler::FileUtils.mkdir('destdir2')
676
+ # Bundler::FileUtils.ln_s('src2.txt', 'destdir2')
677
+ # File.symlink?('destdir2/src2.txt') # => true
678
+ #
679
+ # If +src+ is an array of paths to existing files and +dest+ is a directory,
680
+ # for each child +child+ in +src+ creates a symbolic link <tt>dest/child</tt>
681
+ # pointing to +child+:
682
+ #
683
+ # Bundler::FileUtils.mkdir('srcdir3')
684
+ # Bundler::FileUtils.touch('srcdir3/src0.txt')
685
+ # Bundler::FileUtils.touch('srcdir3/src1.txt')
686
+ # Bundler::FileUtils.mkdir('destdir3')
687
+ # Bundler::FileUtils.ln_s(['srcdir3/src0.txt', 'srcdir3/src1.txt'], 'destdir3')
688
+ # File.symlink?('destdir3/src0.txt') # => true
689
+ # File.symlink?('destdir3/src1.txt') # => true
690
+ #
691
+ # Keyword arguments:
692
+ #
693
+ # - <tt>force: true</tt> - overwrites +dest+ if it exists.
694
+ # - <tt>relative: false</tt> - create links relative to +dest+.
695
+ # - <tt>noop: true</tt> - does not create links.
696
+ # - <tt>verbose: true</tt> - prints an equivalent command:
697
+ #
698
+ # Bundler::FileUtils.ln_s('src0.txt', 'dest0.txt', noop: true, verbose: true)
699
+ # Bundler::FileUtils.ln_s('src1.txt', 'destdir1', noop: true, verbose: true)
700
+ # Bundler::FileUtils.ln_s('src2.txt', 'dest2.txt', force: true, noop: true, verbose: true)
701
+ # Bundler::FileUtils.ln_s(['srcdir3/src0.txt', 'srcdir3/src1.txt'], 'destdir3', noop: true, verbose: true)
702
+ #
703
+ # Output:
704
+ #
705
+ # ln -s src0.txt dest0.txt
706
+ # ln -s src1.txt destdir1
707
+ # ln -sf src2.txt dest2.txt
708
+ # ln -s srcdir3/src0.txt srcdir3/src1.txt destdir3
709
+ #
710
+ # Bundler::FileUtils.symlink is an alias for Bundler::FileUtils.ln_s.
711
+ #
712
+ # Related: Bundler::FileUtils.ln_sf.
713
+ #
714
+ def ln_s(src, dest, force: nil, relative: false, target_directory: true, noop: nil, verbose: nil)
715
+ if relative
716
+ return ln_sr(src, dest, force: force, noop: noop, verbose: verbose)
717
+ end
718
+ fu_output_message "ln -s#{force ? 'f' : ''} #{[src,dest].flatten.join ' '}" if verbose
719
+ return if noop
720
+ fu_each_src_dest0(src, dest) do |s,d|
721
+ remove_file d, true if force
722
+ File.symlink s, d
723
+ end
724
+ end
725
+ module_function :ln_s
726
+
727
+ alias symlink ln_s
728
+ module_function :symlink
729
+
730
+ # Like Bundler::FileUtils.ln_s, but always with keyword argument <tt>force: true</tt> given.
731
+ #
732
+ def ln_sf(src, dest, noop: nil, verbose: nil)
733
+ ln_s src, dest, force: true, noop: noop, verbose: verbose
734
+ end
735
+ module_function :ln_sf
736
+
737
+ # Like Bundler::FileUtils.ln_s, but create links relative to +dest+.
738
+ #
739
+ def ln_sr(src, dest, target_directory: true, force: nil, noop: nil, verbose: nil)
740
+ options = "#{force ? 'f' : ''}#{target_directory ? '' : 'T'}"
741
+ dest = File.path(dest)
742
+ srcs = Array(src)
743
+ link = proc do |s, target_dir_p = true|
744
+ s = File.path(s)
745
+ if target_dir_p
746
+ d = File.join(destdirs = dest, File.basename(s))
747
+ else
748
+ destdirs = File.dirname(d = dest)
749
+ end
750
+ destdirs = fu_split_path(File.realpath(destdirs))
751
+ if fu_starting_path?(s)
752
+ srcdirs = fu_split_path((File.realdirpath(s) rescue File.expand_path(s)))
753
+ base = fu_relative_components_from(srcdirs, destdirs)
754
+ s = File.join(*base)
755
+ else
756
+ srcdirs = fu_clean_components(*fu_split_path(s))
757
+ base = fu_relative_components_from(fu_split_path(Dir.pwd), destdirs)
758
+ while srcdirs.first&. == ".." and base.last&.!=("..") and !fu_starting_path?(base.last)
759
+ srcdirs.shift
760
+ base.pop
761
+ end
762
+ s = File.join(*base, *srcdirs)
763
+ end
764
+ fu_output_message "ln -s#{options} #{s} #{d}" if verbose
765
+ next if noop
766
+ remove_file d, true if force
767
+ File.symlink s, d
768
+ end
769
+ case srcs.size
770
+ when 0
771
+ when 1
772
+ link[srcs[0], target_directory && File.directory?(dest)]
773
+ else
774
+ srcs.each(&link)
775
+ end
776
+ end
777
+ module_function :ln_sr
778
+
779
+ # Creates {hard links}[https://en.wikipedia.org/wiki/Hard_link]; returns +nil+.
780
+ #
781
+ # Arguments +src+ and +dest+
782
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
783
+ #
784
+ # If +src+ is the path to a file and +dest+ does not exist,
785
+ # creates a hard link at +dest+ pointing to +src+:
786
+ #
787
+ # Bundler::FileUtils.touch('src0.txt')
788
+ # File.exist?('dest0.txt') # => false
789
+ # Bundler::FileUtils.link_entry('src0.txt', 'dest0.txt')
790
+ # File.file?('dest0.txt') # => true
791
+ #
792
+ # If +src+ is the path to a directory and +dest+ does not exist,
793
+ # recursively creates hard links at +dest+ pointing to paths in +src+:
794
+ #
795
+ # Bundler::FileUtils.mkdir_p(['src1/dir0', 'src1/dir1'])
796
+ # src_file_paths = [
797
+ # 'src1/dir0/t0.txt',
798
+ # 'src1/dir0/t1.txt',
799
+ # 'src1/dir1/t2.txt',
800
+ # 'src1/dir1/t3.txt',
801
+ # ]
802
+ # Bundler::FileUtils.touch(src_file_paths)
803
+ # File.directory?('dest1') # => true
804
+ # Bundler::FileUtils.link_entry('src1', 'dest1')
805
+ # File.file?('dest1/dir0/t0.txt') # => true
806
+ # File.file?('dest1/dir0/t1.txt') # => true
807
+ # File.file?('dest1/dir1/t2.txt') # => true
808
+ # File.file?('dest1/dir1/t3.txt') # => true
809
+ #
810
+ # Keyword arguments:
811
+ #
812
+ # - <tt>dereference_root: true</tt> - dereferences +src+ if it is a symbolic link.
813
+ # - <tt>remove_destination: true</tt> - removes +dest+ before creating links.
814
+ #
815
+ # Raises an exception if +dest+ is the path to an existing file or directory
816
+ # and keyword argument <tt>remove_destination: true</tt> is not given.
817
+ #
818
+ # Related: Bundler::FileUtils.ln (has different options).
819
+ #
820
+ def link_entry(src, dest, dereference_root = false, remove_destination = false)
821
+ Entry_.new(src, nil, dereference_root).traverse do |ent|
822
+ destent = Entry_.new(dest, ent.rel, false)
823
+ File.unlink destent.path if remove_destination && File.file?(destent.path)
824
+ ent.link destent.path
825
+ end
826
+ end
827
+ module_function :link_entry
828
+
829
+ # Copies files.
830
+ #
831
+ # Arguments +src+ (a single path or an array of paths)
832
+ # and +dest+ (a single path)
833
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
834
+ #
835
+ # If +src+ is the path to a file and +dest+ is not the path to a directory,
836
+ # copies +src+ to +dest+:
837
+ #
838
+ # Bundler::FileUtils.touch('src0.txt')
839
+ # File.exist?('dest0.txt') # => false
840
+ # Bundler::FileUtils.cp('src0.txt', 'dest0.txt')
841
+ # File.file?('dest0.txt') # => true
842
+ #
843
+ # If +src+ is the path to a file and +dest+ is the path to a directory,
844
+ # copies +src+ to <tt>dest/src</tt>:
845
+ #
846
+ # Bundler::FileUtils.touch('src1.txt')
847
+ # Bundler::FileUtils.mkdir('dest1')
848
+ # Bundler::FileUtils.cp('src1.txt', 'dest1')
849
+ # File.file?('dest1/src1.txt') # => true
850
+ #
851
+ # If +src+ is an array of paths to files and +dest+ is the path to a directory,
852
+ # copies from each +src+ to +dest+:
853
+ #
854
+ # src_file_paths = ['src2.txt', 'src2.dat']
855
+ # Bundler::FileUtils.touch(src_file_paths)
856
+ # Bundler::FileUtils.mkdir('dest2')
857
+ # Bundler::FileUtils.cp(src_file_paths, 'dest2')
858
+ # File.file?('dest2/src2.txt') # => true
859
+ # File.file?('dest2/src2.dat') # => true
860
+ #
861
+ # Keyword arguments:
862
+ #
863
+ # - <tt>preserve: true</tt> - preserves file times.
864
+ # - <tt>noop: true</tt> - does not copy files.
865
+ # - <tt>verbose: true</tt> - prints an equivalent command:
866
+ #
867
+ # Bundler::FileUtils.cp('src0.txt', 'dest0.txt', noop: true, verbose: true)
868
+ # Bundler::FileUtils.cp('src1.txt', 'dest1', noop: true, verbose: true)
869
+ # Bundler::FileUtils.cp(src_file_paths, 'dest2', noop: true, verbose: true)
870
+ #
871
+ # Output:
872
+ #
873
+ # cp src0.txt dest0.txt
874
+ # cp src1.txt dest1
875
+ # cp src2.txt src2.dat dest2
876
+ #
877
+ # Raises an exception if +src+ is a directory.
878
+ #
879
+ # Bundler::FileUtils.copy is an alias for Bundler::FileUtils.cp.
880
+ #
881
+ # Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
882
+ #
883
+ def cp(src, dest, preserve: nil, noop: nil, verbose: nil)
884
+ fu_output_message "cp#{preserve ? ' -p' : ''} #{[src,dest].flatten.join ' '}" if verbose
885
+ return if noop
886
+ fu_each_src_dest(src, dest) do |s, d|
887
+ copy_file s, d, preserve
888
+ end
889
+ end
890
+ module_function :cp
891
+
892
+ alias copy cp
893
+ module_function :copy
894
+
895
+ # Recursively copies files.
896
+ #
897
+ # Arguments +src+ (a single path or an array of paths)
898
+ # and +dest+ (a single path)
899
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
900
+ #
901
+ # The mode, owner, and group are retained in the copy;
902
+ # to change those, use Bundler::FileUtils.install instead.
903
+ #
904
+ # If +src+ is the path to a file and +dest+ is not the path to a directory,
905
+ # copies +src+ to +dest+:
906
+ #
907
+ # Bundler::FileUtils.touch('src0.txt')
908
+ # File.exist?('dest0.txt') # => false
909
+ # Bundler::FileUtils.cp_r('src0.txt', 'dest0.txt')
910
+ # File.file?('dest0.txt') # => true
911
+ #
912
+ # If +src+ is the path to a file and +dest+ is the path to a directory,
913
+ # copies +src+ to <tt>dest/src</tt>:
914
+ #
915
+ # Bundler::FileUtils.touch('src1.txt')
916
+ # Bundler::FileUtils.mkdir('dest1')
917
+ # Bundler::FileUtils.cp_r('src1.txt', 'dest1')
918
+ # File.file?('dest1/src1.txt') # => true
919
+ #
920
+ # If +src+ is the path to a directory and +dest+ does not exist,
921
+ # recursively copies +src+ to +dest+:
922
+ #
923
+ # tree('src2')
924
+ # # => src2
925
+ # # |-- dir0
926
+ # # | |-- src0.txt
927
+ # # | `-- src1.txt
928
+ # # `-- dir1
929
+ # # |-- src2.txt
930
+ # # `-- src3.txt
931
+ # Bundler::FileUtils.exist?('dest2') # => false
932
+ # Bundler::FileUtils.cp_r('src2', 'dest2')
933
+ # tree('dest2')
934
+ # # => dest2
935
+ # # |-- dir0
936
+ # # | |-- src0.txt
937
+ # # | `-- src1.txt
938
+ # # `-- dir1
939
+ # # |-- src2.txt
940
+ # # `-- src3.txt
941
+ #
942
+ # If +src+ and +dest+ are paths to directories,
943
+ # recursively copies +src+ to <tt>dest/src</tt>:
944
+ #
945
+ # tree('src3')
946
+ # # => src3
947
+ # # |-- dir0
948
+ # # | |-- src0.txt
949
+ # # | `-- src1.txt
950
+ # # `-- dir1
951
+ # # |-- src2.txt
952
+ # # `-- src3.txt
953
+ # Bundler::FileUtils.mkdir('dest3')
954
+ # Bundler::FileUtils.cp_r('src3', 'dest3')
955
+ # tree('dest3')
956
+ # # => dest3
957
+ # # `-- src3
958
+ # # |-- dir0
959
+ # # | |-- src0.txt
960
+ # # | `-- src1.txt
961
+ # # `-- dir1
962
+ # # |-- src2.txt
963
+ # # `-- src3.txt
964
+ #
965
+ # If +src+ is an array of paths and +dest+ is a directory,
966
+ # recursively copies from each path in +src+ to +dest+;
967
+ # the paths in +src+ may point to files and/or directories.
968
+ #
969
+ # Keyword arguments:
970
+ #
971
+ # - <tt>dereference_root: false</tt> - if +src+ is a symbolic link,
972
+ # does not dereference it.
973
+ # - <tt>noop: true</tt> - does not copy files.
974
+ # - <tt>preserve: true</tt> - preserves file times.
975
+ # - <tt>remove_destination: true</tt> - removes +dest+ before copying files.
976
+ # - <tt>verbose: true</tt> - prints an equivalent command:
977
+ #
978
+ # Bundler::FileUtils.cp_r('src0.txt', 'dest0.txt', noop: true, verbose: true)
979
+ # Bundler::FileUtils.cp_r('src1.txt', 'dest1', noop: true, verbose: true)
980
+ # Bundler::FileUtils.cp_r('src2', 'dest2', noop: true, verbose: true)
981
+ # Bundler::FileUtils.cp_r('src3', 'dest3', noop: true, verbose: true)
982
+ #
983
+ # Output:
984
+ #
985
+ # cp -r src0.txt dest0.txt
986
+ # cp -r src1.txt dest1
987
+ # cp -r src2 dest2
988
+ # cp -r src3 dest3
989
+ #
990
+ # Raises an exception of +src+ is the path to a directory
991
+ # and +dest+ is the path to a file.
992
+ #
993
+ # Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
994
+ #
995
+ def cp_r(src, dest, preserve: nil, noop: nil, verbose: nil,
996
+ dereference_root: true, remove_destination: nil)
997
+ fu_output_message "cp -r#{preserve ? 'p' : ''}#{remove_destination ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if verbose
998
+ return if noop
999
+ fu_each_src_dest(src, dest) do |s, d|
1000
+ copy_entry s, d, preserve, dereference_root, remove_destination
1001
+ end
1002
+ end
1003
+ module_function :cp_r
1004
+
1005
+ # Recursively copies files from +src+ to +dest+.
1006
+ #
1007
+ # Arguments +src+ and +dest+
1008
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
1009
+ #
1010
+ # If +src+ is the path to a file, copies +src+ to +dest+:
1011
+ #
1012
+ # Bundler::FileUtils.touch('src0.txt')
1013
+ # File.exist?('dest0.txt') # => false
1014
+ # Bundler::FileUtils.copy_entry('src0.txt', 'dest0.txt')
1015
+ # File.file?('dest0.txt') # => true
1016
+ #
1017
+ # If +src+ is a directory, recursively copies +src+ to +dest+:
1018
+ #
1019
+ # tree('src1')
1020
+ # # => src1
1021
+ # # |-- dir0
1022
+ # # | |-- src0.txt
1023
+ # # | `-- src1.txt
1024
+ # # `-- dir1
1025
+ # # |-- src2.txt
1026
+ # # `-- src3.txt
1027
+ # Bundler::FileUtils.copy_entry('src1', 'dest1')
1028
+ # tree('dest1')
1029
+ # # => dest1
1030
+ # # |-- dir0
1031
+ # # | |-- src0.txt
1032
+ # # | `-- src1.txt
1033
+ # # `-- dir1
1034
+ # # |-- src2.txt
1035
+ # # `-- src3.txt
1036
+ #
1037
+ # The recursive copying preserves file types for regular files,
1038
+ # directories, and symbolic links;
1039
+ # other file types (FIFO streams, device files, etc.) are not supported.
1040
+ #
1041
+ # Keyword arguments:
1042
+ #
1043
+ # - <tt>dereference_root: true</tt> - if +src+ is a symbolic link,
1044
+ # follows the link.
1045
+ # - <tt>preserve: true</tt> - preserves file times.
1046
+ # - <tt>remove_destination: true</tt> - removes +dest+ before copying files.
1047
+ #
1048
+ # Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
1049
+ #
1050
+ def copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
1051
+ if dereference_root
1052
+ src = File.realpath(src)
1053
+ end
1054
+
1055
+ Entry_.new(src, nil, false).wrap_traverse(proc do |ent|
1056
+ destent = Entry_.new(dest, ent.rel, false)
1057
+ File.unlink destent.path if remove_destination && (File.file?(destent.path) || File.symlink?(destent.path))
1058
+ ent.copy destent.path
1059
+ end, proc do |ent|
1060
+ destent = Entry_.new(dest, ent.rel, false)
1061
+ ent.copy_metadata destent.path if preserve
1062
+ end)
1063
+ end
1064
+ module_function :copy_entry
1065
+
1066
+ # Copies file from +src+ to +dest+, which should not be directories.
1067
+ #
1068
+ # Arguments +src+ and +dest+
1069
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
1070
+ #
1071
+ # Examples:
1072
+ #
1073
+ # Bundler::FileUtils.touch('src0.txt')
1074
+ # Bundler::FileUtils.copy_file('src0.txt', 'dest0.txt')
1075
+ # File.file?('dest0.txt') # => true
1076
+ #
1077
+ # Keyword arguments:
1078
+ #
1079
+ # - <tt>dereference: false</tt> - if +src+ is a symbolic link,
1080
+ # does not follow the link.
1081
+ # - <tt>preserve: true</tt> - preserves file times.
1082
+ # - <tt>remove_destination: true</tt> - removes +dest+ before copying files.
1083
+ #
1084
+ # Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
1085
+ #
1086
+ def copy_file(src, dest, preserve = false, dereference = true)
1087
+ ent = Entry_.new(src, nil, dereference)
1088
+ ent.copy_file dest
1089
+ ent.copy_metadata dest if preserve
1090
+ end
1091
+ module_function :copy_file
1092
+
1093
+ # Copies \IO stream +src+ to \IO stream +dest+ via
1094
+ # {IO.copy_stream}[https://docs.ruby-lang.org/en/master/IO.html#method-c-copy_stream].
1095
+ #
1096
+ # Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
1097
+ #
1098
+ def copy_stream(src, dest)
1099
+ IO.copy_stream(src, dest)
1100
+ end
1101
+ module_function :copy_stream
1102
+
1103
+ # Moves entries.
1104
+ #
1105
+ # Arguments +src+ (a single path or an array of paths)
1106
+ # and +dest+ (a single path)
1107
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
1108
+ #
1109
+ # If +src+ and +dest+ are on different file systems,
1110
+ # first copies, then removes +src+.
1111
+ #
1112
+ # May cause a local vulnerability if not called with keyword argument
1113
+ # <tt>secure: true</tt>;
1114
+ # see {Avoiding the TOCTTOU Vulnerability}[rdoc-ref:FileUtils@Avoiding+the+TOCTTOU+Vulnerability].
1115
+ #
1116
+ # If +src+ is the path to a single file or directory and +dest+ does not exist,
1117
+ # moves +src+ to +dest+:
1118
+ #
1119
+ # tree('src0')
1120
+ # # => src0
1121
+ # # |-- src0.txt
1122
+ # # `-- src1.txt
1123
+ # File.exist?('dest0') # => false
1124
+ # Bundler::FileUtils.mv('src0', 'dest0')
1125
+ # File.exist?('src0') # => false
1126
+ # tree('dest0')
1127
+ # # => dest0
1128
+ # # |-- src0.txt
1129
+ # # `-- src1.txt
1130
+ #
1131
+ # If +src+ is an array of paths to files and directories
1132
+ # and +dest+ is the path to a directory,
1133
+ # copies from each path in the array to +dest+:
1134
+ #
1135
+ # File.file?('src1.txt') # => true
1136
+ # tree('src1')
1137
+ # # => src1
1138
+ # # |-- src.dat
1139
+ # # `-- src.txt
1140
+ # Dir.empty?('dest1') # => true
1141
+ # Bundler::FileUtils.mv(['src1.txt', 'src1'], 'dest1')
1142
+ # tree('dest1')
1143
+ # # => dest1
1144
+ # # |-- src1
1145
+ # # | |-- src.dat
1146
+ # # | `-- src.txt
1147
+ # # `-- src1.txt
1148
+ #
1149
+ # Keyword arguments:
1150
+ #
1151
+ # - <tt>force: true</tt> - if the move includes removing +src+
1152
+ # (that is, if +src+ and +dest+ are on different file systems),
1153
+ # ignores raised exceptions of StandardError and its descendants.
1154
+ # - <tt>noop: true</tt> - does not move files.
1155
+ # - <tt>secure: true</tt> - removes +src+ securely;
1156
+ # see details at Bundler::FileUtils.remove_entry_secure.
1157
+ # - <tt>verbose: true</tt> - prints an equivalent command:
1158
+ #
1159
+ # Bundler::FileUtils.mv('src0', 'dest0', noop: true, verbose: true)
1160
+ # Bundler::FileUtils.mv(['src1.txt', 'src1'], 'dest1', noop: true, verbose: true)
1161
+ #
1162
+ # Output:
1163
+ #
1164
+ # mv src0 dest0
1165
+ # mv src1.txt src1 dest1
1166
+ #
1167
+ # Bundler::FileUtils.move is an alias for Bundler::FileUtils.mv.
1168
+ #
1169
+ def mv(src, dest, force: nil, noop: nil, verbose: nil, secure: nil)
1170
+ fu_output_message "mv#{force ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if verbose
1171
+ return if noop
1172
+ fu_each_src_dest(src, dest) do |s, d|
1173
+ destent = Entry_.new(d, nil, true)
1174
+ begin
1175
+ if destent.exist?
1176
+ if destent.directory?
1177
+ raise Errno::EEXIST, d
1178
+ end
1179
+ end
1180
+ begin
1181
+ File.rename s, d
1182
+ rescue Errno::EXDEV,
1183
+ Errno::EPERM # move from unencrypted to encrypted dir (ext4)
1184
+ copy_entry s, d, true
1185
+ if secure
1186
+ remove_entry_secure s, force
1187
+ else
1188
+ remove_entry s, force
1189
+ end
1190
+ end
1191
+ rescue SystemCallError
1192
+ raise unless force
1193
+ end
1194
+ end
1195
+ end
1196
+ module_function :mv
1197
+
1198
+ alias move mv
1199
+ module_function :move
1200
+
1201
+ # Removes entries at the paths in the given +list+
1202
+ # (a single path or an array of paths)
1203
+ # returns +list+, if it is an array, <tt>[list]</tt> otherwise.
1204
+ #
1205
+ # Argument +list+ or its elements
1206
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
1207
+ #
1208
+ # With no keyword arguments, removes files at the paths given in +list+:
1209
+ #
1210
+ # Bundler::FileUtils.touch(['src0.txt', 'src0.dat'])
1211
+ # Bundler::FileUtils.rm(['src0.dat', 'src0.txt']) # => ["src0.dat", "src0.txt"]
1212
+ #
1213
+ # Keyword arguments:
1214
+ #
1215
+ # - <tt>force: true</tt> - ignores raised exceptions of StandardError
1216
+ # and its descendants.
1217
+ # - <tt>noop: true</tt> - does not remove files; returns +nil+.
1218
+ # - <tt>verbose: true</tt> - prints an equivalent command:
1219
+ #
1220
+ # Bundler::FileUtils.rm(['src0.dat', 'src0.txt'], noop: true, verbose: true)
1221
+ #
1222
+ # Output:
1223
+ #
1224
+ # rm src0.dat src0.txt
1225
+ #
1226
+ # Bundler::FileUtils.remove is an alias for Bundler::FileUtils.rm.
1227
+ #
1228
+ # Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
1229
+ #
1230
+ def rm(list, force: nil, noop: nil, verbose: nil)
1231
+ list = fu_list(list)
1232
+ fu_output_message "rm#{force ? ' -f' : ''} #{list.join ' '}" if verbose
1233
+ return if noop
1234
+
1235
+ list.each do |path|
1236
+ remove_file path, force
1237
+ end
1238
+ end
1239
+ module_function :rm
1240
+
1241
+ alias remove rm
1242
+ module_function :remove
1243
+
1244
+ # Equivalent to:
1245
+ #
1246
+ # Bundler::FileUtils.rm(list, force: true, **kwargs)
1247
+ #
1248
+ # Argument +list+ (a single path or an array of paths)
1249
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
1250
+ #
1251
+ # See Bundler::FileUtils.rm for keyword arguments.
1252
+ #
1253
+ # Bundler::FileUtils.safe_unlink is an alias for Bundler::FileUtils.rm_f.
1254
+ #
1255
+ # Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
1256
+ #
1257
+ def rm_f(list, noop: nil, verbose: nil)
1258
+ rm list, force: true, noop: noop, verbose: verbose
1259
+ end
1260
+ module_function :rm_f
1261
+
1262
+ alias safe_unlink rm_f
1263
+ module_function :safe_unlink
1264
+
1265
+ # Removes entries at the paths in the given +list+
1266
+ # (a single path or an array of paths);
1267
+ # returns +list+, if it is an array, <tt>[list]</tt> otherwise.
1268
+ #
1269
+ # Argument +list+ or its elements
1270
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
1271
+ #
1272
+ # May cause a local vulnerability if not called with keyword argument
1273
+ # <tt>secure: true</tt>;
1274
+ # see {Avoiding the TOCTTOU Vulnerability}[rdoc-ref:FileUtils@Avoiding+the+TOCTTOU+Vulnerability].
1275
+ #
1276
+ # For each file path, removes the file at that path:
1277
+ #
1278
+ # Bundler::FileUtils.touch(['src0.txt', 'src0.dat'])
1279
+ # Bundler::FileUtils.rm_r(['src0.dat', 'src0.txt'])
1280
+ # File.exist?('src0.txt') # => false
1281
+ # File.exist?('src0.dat') # => false
1282
+ #
1283
+ # For each directory path, recursively removes files and directories:
1284
+ #
1285
+ # tree('src1')
1286
+ # # => src1
1287
+ # # |-- dir0
1288
+ # # | |-- src0.txt
1289
+ # # | `-- src1.txt
1290
+ # # `-- dir1
1291
+ # # |-- src2.txt
1292
+ # # `-- src3.txt
1293
+ # Bundler::FileUtils.rm_r('src1')
1294
+ # File.exist?('src1') # => false
1295
+ #
1296
+ # Keyword arguments:
1297
+ #
1298
+ # - <tt>force: true</tt> - ignores raised exceptions of StandardError
1299
+ # and its descendants.
1300
+ # - <tt>noop: true</tt> - does not remove entries; returns +nil+.
1301
+ # - <tt>secure: true</tt> - removes +src+ securely;
1302
+ # see details at Bundler::FileUtils.remove_entry_secure.
1303
+ # - <tt>verbose: true</tt> - prints an equivalent command:
1304
+ #
1305
+ # Bundler::FileUtils.rm_r(['src0.dat', 'src0.txt'], noop: true, verbose: true)
1306
+ # Bundler::FileUtils.rm_r('src1', noop: true, verbose: true)
1307
+ #
1308
+ # Output:
1309
+ #
1310
+ # rm -r src0.dat src0.txt
1311
+ # rm -r src1
1312
+ #
1313
+ # Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
1314
+ #
1315
+ def rm_r(list, force: nil, noop: nil, verbose: nil, secure: nil)
1316
+ list = fu_list(list)
1317
+ fu_output_message "rm -r#{force ? 'f' : ''} #{list.join ' '}" if verbose
1318
+ return if noop
1319
+ list.each do |path|
1320
+ if secure
1321
+ remove_entry_secure path, force
1322
+ else
1323
+ remove_entry path, force
1324
+ end
1325
+ end
1326
+ end
1327
+ module_function :rm_r
1328
+
1329
+ # Equivalent to:
1330
+ #
1331
+ # Bundler::FileUtils.rm_r(list, force: true, **kwargs)
1332
+ #
1333
+ # Argument +list+ or its elements
1334
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
1335
+ #
1336
+ # May cause a local vulnerability if not called with keyword argument
1337
+ # <tt>secure: true</tt>;
1338
+ # see {Avoiding the TOCTTOU Vulnerability}[rdoc-ref:FileUtils@Avoiding+the+TOCTTOU+Vulnerability].
1339
+ #
1340
+ # See Bundler::FileUtils.rm_r for keyword arguments.
1341
+ #
1342
+ # Bundler::FileUtils.rmtree is an alias for Bundler::FileUtils.rm_rf.
1343
+ #
1344
+ # Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
1345
+ #
1346
+ def rm_rf(list, noop: nil, verbose: nil, secure: nil)
1347
+ rm_r list, force: true, noop: noop, verbose: verbose, secure: secure
1348
+ end
1349
+ module_function :rm_rf
1350
+
1351
+ alias rmtree rm_rf
1352
+ module_function :rmtree
1353
+
1354
+ # Securely removes the entry given by +path+,
1355
+ # which should be the entry for a regular file, a symbolic link,
1356
+ # or a directory.
1357
+ #
1358
+ # Argument +path+
1359
+ # should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
1360
+ #
1361
+ # Avoids a local vulnerability that can exist in certain circumstances;
1362
+ # see {Avoiding the TOCTTOU Vulnerability}[rdoc-ref:FileUtils@Avoiding+the+TOCTTOU+Vulnerability].
1363
+ #
1364
+ # Optional argument +force+ specifies whether to ignore
1365
+ # raised exceptions of StandardError and its descendants.
1366
+ #
1367
+ # Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
1368
+ #
1369
+ def remove_entry_secure(path, force = false)
1370
+ unless fu_have_symlink?
1371
+ remove_entry path, force
1372
+ return
1373
+ end
1374
+ fullpath = File.expand_path(path)
1375
+ st = File.lstat(fullpath)
1376
+ unless st.directory?
1377
+ File.unlink fullpath
1378
+ return
1379
+ end
1380
+ # is a directory.
1381
+ parent_st = File.stat(File.dirname(fullpath))
1382
+ unless parent_st.world_writable?
1383
+ remove_entry path, force
1384
+ return
1385
+ end
1386
+ unless parent_st.sticky?
1387
+ raise ArgumentError, "parent directory is world writable, Bundler::FileUtils#remove_entry_secure does not work; abort: #{path.inspect} (parent directory mode #{'%o' % parent_st.mode})"
1388
+ end
1389
+
1390
+ # freeze tree root
1391
+ euid = Process.euid
1392
+ dot_file = fullpath + "/."
1393
+ begin
1394
+ File.open(dot_file) {|f|
1395
+ unless fu_stat_identical_entry?(st, f.stat)
1396
+ # symlink (TOC-to-TOU attack?)
1397
+ File.unlink fullpath
1398
+ return
1399
+ end
1400
+ f.chown euid, -1
1401
+ f.chmod 0700
1402
+ }
1403
+ rescue Errno::EISDIR # JRuby in non-native mode can't open files as dirs
1404
+ File.lstat(dot_file).tap {|fstat|
1405
+ unless fu_stat_identical_entry?(st, fstat)
1406
+ # symlink (TOC-to-TOU attack?)
1407
+ File.unlink fullpath
1408
+ return
1409
+ end
1410
+ File.chown euid, -1, dot_file
1411
+ File.chmod 0700, dot_file
1412
+ }
1413
+ end
1414
+
1415
+ unless fu_stat_identical_entry?(st, File.lstat(fullpath))
1416
+ # TOC-to-TOU attack?
1417
+ File.unlink fullpath
1418
+ return
1419
+ end
1420
+
1421
+ # ---- tree root is frozen ----
1422
+ root = Entry_.new(path)
1423
+ root.preorder_traverse do |ent|
1424
+ if ent.directory?
1425
+ ent.chown euid, -1
1426
+ ent.chmod 0700
1427
+ end
1428
+ end
1429
+ root.postorder_traverse do |ent|
1430
+ begin
1431
+ ent.remove
1432
+ rescue
1433
+ raise unless force
1434
+ end
1435
+ end
1436
+ rescue
1437
+ raise unless force
1438
+ end
1439
+ module_function :remove_entry_secure
1440
+
1441
+ def fu_have_symlink? #:nodoc:
1442
+ File.symlink nil, nil
1443
+ rescue NotImplementedError
1444
+ return false
1445
+ rescue TypeError
1446
+ return true
1447
+ end
1448
+ private_module_function :fu_have_symlink?
1449
+
1450
+ def fu_stat_identical_entry?(a, b) #:nodoc:
1451
+ a.dev == b.dev and a.ino == b.ino
1452
+ end
1453
+ private_module_function :fu_stat_identical_entry?
1454
+
1455
+ # Removes the entry given by +path+,
1456
+ # which should be the entry for a regular file, a symbolic link,
1457
+ # or a directory.
1458
+ #
1459
+ # Argument +path+
1460
+ # should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
1461
+ #
1462
+ # Optional argument +force+ specifies whether to ignore
1463
+ # raised exceptions of StandardError and its descendants.
1464
+ #
1465
+ # Related: Bundler::FileUtils.remove_entry_secure.
1466
+ #
1467
+ def remove_entry(path, force = false)
1468
+ Entry_.new(path).postorder_traverse do |ent|
1469
+ begin
1470
+ ent.remove
1471
+ rescue
1472
+ raise unless force
1473
+ end
1474
+ end
1475
+ rescue
1476
+ raise unless force
1477
+ end
1478
+ module_function :remove_entry
1479
+
1480
+ # Removes the file entry given by +path+,
1481
+ # which should be the entry for a regular file or a symbolic link.
1482
+ #
1483
+ # Argument +path+
1484
+ # should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
1485
+ #
1486
+ # Optional argument +force+ specifies whether to ignore
1487
+ # raised exceptions of StandardError and its descendants.
1488
+ #
1489
+ # Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
1490
+ #
1491
+ def remove_file(path, force = false)
1492
+ Entry_.new(path).remove_file
1493
+ rescue
1494
+ raise unless force
1495
+ end
1496
+ module_function :remove_file
1497
+
1498
+ # Recursively removes the directory entry given by +path+,
1499
+ # which should be the entry for a regular file, a symbolic link,
1500
+ # or a directory.
1501
+ #
1502
+ # Argument +path+
1503
+ # should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
1504
+ #
1505
+ # Optional argument +force+ specifies whether to ignore
1506
+ # raised exceptions of StandardError and its descendants.
1507
+ #
1508
+ # Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
1509
+ #
1510
+ def remove_dir(path, force = false)
1511
+ remove_entry path, force # FIXME?? check if it is a directory
1512
+ end
1513
+ module_function :remove_dir
1514
+
1515
+ # Returns +true+ if the contents of files +a+ and +b+ are identical,
1516
+ # +false+ otherwise.
1517
+ #
1518
+ # Arguments +a+ and +b+
1519
+ # should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
1520
+ #
1521
+ # Bundler::FileUtils.identical? and Bundler::FileUtils.cmp are aliases for Bundler::FileUtils.compare_file.
1522
+ #
1523
+ # Related: Bundler::FileUtils.compare_stream.
1524
+ #
1525
+ def compare_file(a, b)
1526
+ return false unless File.size(a) == File.size(b)
1527
+ File.open(a, 'rb') {|fa|
1528
+ File.open(b, 'rb') {|fb|
1529
+ return compare_stream(fa, fb)
1530
+ }
1531
+ }
1532
+ end
1533
+ module_function :compare_file
1534
+
1535
+ alias identical? compare_file
1536
+ alias cmp compare_file
1537
+ module_function :identical?
1538
+ module_function :cmp
1539
+
1540
+ # Returns +true+ if the contents of streams +a+ and +b+ are identical,
1541
+ # +false+ otherwise.
1542
+ #
1543
+ # Arguments +a+ and +b+
1544
+ # should be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
1545
+ #
1546
+ # Related: Bundler::FileUtils.compare_file.
1547
+ #
1548
+ def compare_stream(a, b)
1549
+ bsize = fu_stream_blksize(a, b)
1550
+
1551
+ sa = String.new(capacity: bsize)
1552
+ sb = String.new(capacity: bsize)
1553
+
1554
+ begin
1555
+ a.read(bsize, sa)
1556
+ b.read(bsize, sb)
1557
+ return true if sa.empty? && sb.empty?
1558
+ end while sa == sb
1559
+ false
1560
+ end
1561
+ module_function :compare_stream
1562
+
1563
+ # Copies a file entry.
1564
+ # See {install(1)}[https://man7.org/linux/man-pages/man1/install.1.html].
1565
+ #
1566
+ # Arguments +src+ (a single path or an array of paths)
1567
+ # and +dest+ (a single path)
1568
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments];
1569
+ #
1570
+ # If the entry at +dest+ does not exist, copies from +src+ to +dest+:
1571
+ #
1572
+ # File.read('src0.txt') # => "aaa\n"
1573
+ # File.exist?('dest0.txt') # => false
1574
+ # Bundler::FileUtils.install('src0.txt', 'dest0.txt')
1575
+ # File.read('dest0.txt') # => "aaa\n"
1576
+ #
1577
+ # If +dest+ is a file entry, copies from +src+ to +dest+, overwriting:
1578
+ #
1579
+ # File.read('src1.txt') # => "aaa\n"
1580
+ # File.read('dest1.txt') # => "bbb\n"
1581
+ # Bundler::FileUtils.install('src1.txt', 'dest1.txt')
1582
+ # File.read('dest1.txt') # => "aaa\n"
1583
+ #
1584
+ # If +dest+ is a directory entry, copies from +src+ to <tt>dest/src</tt>,
1585
+ # overwriting if necessary:
1586
+ #
1587
+ # File.read('src2.txt') # => "aaa\n"
1588
+ # File.read('dest2/src2.txt') # => "bbb\n"
1589
+ # Bundler::FileUtils.install('src2.txt', 'dest2')
1590
+ # File.read('dest2/src2.txt') # => "aaa\n"
1591
+ #
1592
+ # If +src+ is an array of paths and +dest+ points to a directory,
1593
+ # copies each path +path+ in +src+ to <tt>dest/path</tt>:
1594
+ #
1595
+ # File.file?('src3.txt') # => true
1596
+ # File.file?('src3.dat') # => true
1597
+ # Bundler::FileUtils.mkdir('dest3')
1598
+ # Bundler::FileUtils.install(['src3.txt', 'src3.dat'], 'dest3')
1599
+ # File.file?('dest3/src3.txt') # => true
1600
+ # File.file?('dest3/src3.dat') # => true
1601
+ #
1602
+ # Keyword arguments:
1603
+ #
1604
+ # - <tt>group: <i>group</i></tt> - changes the group if not +nil+,
1605
+ # using {File.chown}[https://docs.ruby-lang.org/en/master/File.html#method-c-chown].
1606
+ # - <tt>mode: <i>permissions</i></tt> - changes the permissions.
1607
+ # using {File.chmod}[https://docs.ruby-lang.org/en/master/File.html#method-c-chmod].
1608
+ # - <tt>noop: true</tt> - does not copy entries; returns +nil+.
1609
+ # - <tt>owner: <i>owner</i></tt> - changes the owner if not +nil+,
1610
+ # using {File.chown}[https://docs.ruby-lang.org/en/master/File.html#method-c-chown].
1611
+ # - <tt>preserve: true</tt> - preserve timestamps
1612
+ # using {File.utime}[https://docs.ruby-lang.org/en/master/File.html#method-c-utime].
1613
+ # - <tt>verbose: true</tt> - prints an equivalent command:
1614
+ #
1615
+ # Bundler::FileUtils.install('src0.txt', 'dest0.txt', noop: true, verbose: true)
1616
+ # Bundler::FileUtils.install('src1.txt', 'dest1.txt', noop: true, verbose: true)
1617
+ # Bundler::FileUtils.install('src2.txt', 'dest2', noop: true, verbose: true)
1618
+ #
1619
+ # Output:
1620
+ #
1621
+ # install -c src0.txt dest0.txt
1622
+ # install -c src1.txt dest1.txt
1623
+ # install -c src2.txt dest2
1624
+ #
1625
+ # Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
1626
+ #
1627
+ def install(src, dest, mode: nil, owner: nil, group: nil, preserve: nil,
1628
+ noop: nil, verbose: nil)
1629
+ if verbose
1630
+ msg = +"install -c"
1631
+ msg << ' -p' if preserve
1632
+ msg << ' -m ' << mode_to_s(mode) if mode
1633
+ msg << " -o #{owner}" if owner
1634
+ msg << " -g #{group}" if group
1635
+ msg << ' ' << [src,dest].flatten.join(' ')
1636
+ fu_output_message msg
1637
+ end
1638
+ return if noop
1639
+ uid = fu_get_uid(owner)
1640
+ gid = fu_get_gid(group)
1641
+ fu_each_src_dest(src, dest) do |s, d|
1642
+ st = File.stat(s)
1643
+ unless File.exist?(d) and compare_file(s, d)
1644
+ remove_file d, true
1645
+ copy_file s, d
1646
+ File.utime st.atime, st.mtime, d if preserve
1647
+ File.chmod fu_mode(mode, st), d if mode
1648
+ File.chown uid, gid, d if uid or gid
1649
+ end
1650
+ end
1651
+ end
1652
+ module_function :install
1653
+
1654
+ def user_mask(target) #:nodoc:
1655
+ target.each_char.inject(0) do |mask, chr|
1656
+ case chr
1657
+ when "u"
1658
+ mask | 04700
1659
+ when "g"
1660
+ mask | 02070
1661
+ when "o"
1662
+ mask | 01007
1663
+ when "a"
1664
+ mask | 07777
1665
+ else
1666
+ raise ArgumentError, "invalid `who' symbol in file mode: #{chr}"
1667
+ end
1668
+ end
1669
+ end
1670
+ private_module_function :user_mask
1671
+
1672
+ def apply_mask(mode, user_mask, op, mode_mask) #:nodoc:
1673
+ case op
1674
+ when '='
1675
+ (mode & ~user_mask) | (user_mask & mode_mask)
1676
+ when '+'
1677
+ mode | (user_mask & mode_mask)
1678
+ when '-'
1679
+ mode & ~(user_mask & mode_mask)
1680
+ end
1681
+ end
1682
+ private_module_function :apply_mask
1683
+
1684
+ def symbolic_modes_to_i(mode_sym, path) #:nodoc:
1685
+ path = File.stat(path) unless File::Stat === path
1686
+ mode = path.mode
1687
+ mode_sym.split(/,/).inject(mode & 07777) do |current_mode, clause|
1688
+ target, *actions = clause.split(/([=+-])/)
1689
+ raise ArgumentError, "invalid file mode: #{mode_sym}" if actions.empty?
1690
+ target = 'a' if target.empty?
1691
+ user_mask = user_mask(target)
1692
+ actions.each_slice(2) do |op, perm|
1693
+ need_apply = op == '='
1694
+ mode_mask = (perm || '').each_char.inject(0) do |mask, chr|
1695
+ case chr
1696
+ when "r"
1697
+ mask | 0444
1698
+ when "w"
1699
+ mask | 0222
1700
+ when "x"
1701
+ mask | 0111
1702
+ when "X"
1703
+ if path.directory?
1704
+ mask | 0111
1705
+ else
1706
+ mask
1707
+ end
1708
+ when "s"
1709
+ mask | 06000
1710
+ when "t"
1711
+ mask | 01000
1712
+ when "u", "g", "o"
1713
+ if mask.nonzero?
1714
+ current_mode = apply_mask(current_mode, user_mask, op, mask)
1715
+ end
1716
+ need_apply = false
1717
+ copy_mask = user_mask(chr)
1718
+ (current_mode & copy_mask) / (copy_mask & 0111) * (user_mask & 0111)
1719
+ else
1720
+ raise ArgumentError, "invalid `perm' symbol in file mode: #{chr}"
1721
+ end
1722
+ end
1723
+
1724
+ if mode_mask.nonzero? || need_apply
1725
+ current_mode = apply_mask(current_mode, user_mask, op, mode_mask)
1726
+ end
1727
+ end
1728
+ current_mode
1729
+ end
1730
+ end
1731
+ private_module_function :symbolic_modes_to_i
1732
+
1733
+ def fu_mode(mode, path) #:nodoc:
1734
+ mode.is_a?(String) ? symbolic_modes_to_i(mode, path) : mode
1735
+ end
1736
+ private_module_function :fu_mode
1737
+
1738
+ def mode_to_s(mode) #:nodoc:
1739
+ mode.is_a?(String) ? mode : "%o" % mode
1740
+ end
1741
+ private_module_function :mode_to_s
1742
+
1743
+ # Changes permissions on the entries at the paths given in +list+
1744
+ # (a single path or an array of paths)
1745
+ # to the permissions given by +mode+;
1746
+ # returns +list+ if it is an array, <tt>[list]</tt> otherwise:
1747
+ #
1748
+ # - Modifies each entry that is a regular file using
1749
+ # {File.chmod}[https://docs.ruby-lang.org/en/master/File.html#method-c-chmod].
1750
+ # - Modifies each entry that is a symbolic link using
1751
+ # {File.lchmod}[https://docs.ruby-lang.org/en/master/File.html#method-c-lchmod].
1752
+ #
1753
+ # Argument +list+ or its elements
1754
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
1755
+ #
1756
+ # Argument +mode+ may be either an integer or a string:
1757
+ #
1758
+ # - \Integer +mode+: represents the permission bits to be set:
1759
+ #
1760
+ # Bundler::FileUtils.chmod(0755, 'src0.txt')
1761
+ # Bundler::FileUtils.chmod(0644, ['src0.txt', 'src0.dat'])
1762
+ #
1763
+ # - \String +mode+: represents the permissions to be set:
1764
+ #
1765
+ # The string is of the form <tt>[targets][[operator][perms[,perms]]</tt>, where:
1766
+ #
1767
+ # - +targets+ may be any combination of these letters:
1768
+ #
1769
+ # - <tt>'u'</tt>: permissions apply to the file's owner.
1770
+ # - <tt>'g'</tt>: permissions apply to users in the file's group.
1771
+ # - <tt>'o'</tt>: permissions apply to other users not in the file's group.
1772
+ # - <tt>'a'</tt> (the default): permissions apply to all users.
1773
+ #
1774
+ # - +operator+ may be one of these letters:
1775
+ #
1776
+ # - <tt>'+'</tt>: adds permissions.
1777
+ # - <tt>'-'</tt>: removes permissions.
1778
+ # - <tt>'='</tt>: sets (replaces) permissions.
1779
+ #
1780
+ # - +perms+ (may be repeated, with separating commas)
1781
+ # may be any combination of these letters:
1782
+ #
1783
+ # - <tt>'r'</tt>: Read.
1784
+ # - <tt>'w'</tt>: Write.
1785
+ # - <tt>'x'</tt>: Execute (search, for a directory).
1786
+ # - <tt>'X'</tt>: Search (for a directories only;
1787
+ # must be used with <tt>'+'</tt>)
1788
+ # - <tt>'s'</tt>: Uid or gid.
1789
+ # - <tt>'t'</tt>: Sticky bit.
1790
+ #
1791
+ # Examples:
1792
+ #
1793
+ # Bundler::FileUtils.chmod('u=wrx,go=rx', 'src1.txt')
1794
+ # Bundler::FileUtils.chmod('u=wrx,go=rx', '/usr/bin/ruby')
1795
+ #
1796
+ # Keyword arguments:
1797
+ #
1798
+ # - <tt>noop: true</tt> - does not change permissions; returns +nil+.
1799
+ # - <tt>verbose: true</tt> - prints an equivalent command:
1800
+ #
1801
+ # Bundler::FileUtils.chmod(0755, 'src0.txt', noop: true, verbose: true)
1802
+ # Bundler::FileUtils.chmod(0644, ['src0.txt', 'src0.dat'], noop: true, verbose: true)
1803
+ # Bundler::FileUtils.chmod('u=wrx,go=rx', 'src1.txt', noop: true, verbose: true)
1804
+ # Bundler::FileUtils.chmod('u=wrx,go=rx', '/usr/bin/ruby', noop: true, verbose: true)
1805
+ #
1806
+ # Output:
1807
+ #
1808
+ # chmod 755 src0.txt
1809
+ # chmod 644 src0.txt src0.dat
1810
+ # chmod u=wrx,go=rx src1.txt
1811
+ # chmod u=wrx,go=rx /usr/bin/ruby
1812
+ #
1813
+ # Related: Bundler::FileUtils.chmod_R.
1814
+ #
1815
+ def chmod(mode, list, noop: nil, verbose: nil)
1816
+ list = fu_list(list)
1817
+ fu_output_message sprintf('chmod %s %s', mode_to_s(mode), list.join(' ')) if verbose
1818
+ return if noop
1819
+ list.each do |path|
1820
+ Entry_.new(path).chmod(fu_mode(mode, path))
1821
+ end
1822
+ end
1823
+ module_function :chmod
1824
+
1825
+ # Like Bundler::FileUtils.chmod, but changes permissions recursively.
1826
+ #
1827
+ def chmod_R(mode, list, noop: nil, verbose: nil, force: nil)
1828
+ list = fu_list(list)
1829
+ fu_output_message sprintf('chmod -R%s %s %s',
1830
+ (force ? 'f' : ''),
1831
+ mode_to_s(mode), list.join(' ')) if verbose
1832
+ return if noop
1833
+ list.each do |root|
1834
+ Entry_.new(root).traverse do |ent|
1835
+ begin
1836
+ ent.chmod(fu_mode(mode, ent.path))
1837
+ rescue
1838
+ raise unless force
1839
+ end
1840
+ end
1841
+ end
1842
+ end
1843
+ module_function :chmod_R
1844
+
1845
+ # Changes the owner and group on the entries at the paths given in +list+
1846
+ # (a single path or an array of paths)
1847
+ # to the given +user+ and +group+;
1848
+ # returns +list+ if it is an array, <tt>[list]</tt> otherwise:
1849
+ #
1850
+ # - Modifies each entry that is a regular file using
1851
+ # {File.chown}[https://docs.ruby-lang.org/en/master/File.html#method-c-chown].
1852
+ # - Modifies each entry that is a symbolic link using
1853
+ # {File.lchown}[https://docs.ruby-lang.org/en/master/File.html#method-c-lchown].
1854
+ #
1855
+ # Argument +list+ or its elements
1856
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
1857
+ #
1858
+ # User and group:
1859
+ #
1860
+ # - Argument +user+ may be a user name or a user id;
1861
+ # if +nil+ or +-1+, the user is not changed.
1862
+ # - Argument +group+ may be a group name or a group id;
1863
+ # if +nil+ or +-1+, the group is not changed.
1864
+ # - The user must be a member of the group.
1865
+ #
1866
+ # Examples:
1867
+ #
1868
+ # # One path.
1869
+ # # User and group as string names.
1870
+ # File.stat('src0.txt').uid # => 1004
1871
+ # File.stat('src0.txt').gid # => 1004
1872
+ # Bundler::FileUtils.chown('user2', 'group1', 'src0.txt')
1873
+ # File.stat('src0.txt').uid # => 1006
1874
+ # File.stat('src0.txt').gid # => 1005
1875
+ #
1876
+ # # User and group as uid and gid.
1877
+ # Bundler::FileUtils.chown(1004, 1004, 'src0.txt')
1878
+ # File.stat('src0.txt').uid # => 1004
1879
+ # File.stat('src0.txt').gid # => 1004
1880
+ #
1881
+ # # Array of paths.
1882
+ # Bundler::FileUtils.chown(1006, 1005, ['src0.txt', 'src0.dat'])
1883
+ #
1884
+ # # Directory (not recursive).
1885
+ # Bundler::FileUtils.chown('user2', 'group1', '.')
1886
+ #
1887
+ # Keyword arguments:
1888
+ #
1889
+ # - <tt>noop: true</tt> - does not change permissions; returns +nil+.
1890
+ # - <tt>verbose: true</tt> - prints an equivalent command:
1891
+ #
1892
+ # Bundler::FileUtils.chown('user2', 'group1', 'src0.txt', noop: true, verbose: true)
1893
+ # Bundler::FileUtils.chown(1004, 1004, 'src0.txt', noop: true, verbose: true)
1894
+ # Bundler::FileUtils.chown(1006, 1005, ['src0.txt', 'src0.dat'], noop: true, verbose: true)
1895
+ # Bundler::FileUtils.chown('user2', 'group1', path, noop: true, verbose: true)
1896
+ # Bundler::FileUtils.chown('user2', 'group1', '.', noop: true, verbose: true)
1897
+ #
1898
+ # Output:
1899
+ #
1900
+ # chown user2:group1 src0.txt
1901
+ # chown 1004:1004 src0.txt
1902
+ # chown 1006:1005 src0.txt src0.dat
1903
+ # chown user2:group1 src0.txt
1904
+ # chown user2:group1 .
1905
+ #
1906
+ # Related: Bundler::FileUtils.chown_R.
1907
+ #
1908
+ def chown(user, group, list, noop: nil, verbose: nil)
1909
+ list = fu_list(list)
1910
+ fu_output_message sprintf('chown %s %s',
1911
+ (group ? "#{user}:#{group}" : user || ':'),
1912
+ list.join(' ')) if verbose
1913
+ return if noop
1914
+ uid = fu_get_uid(user)
1915
+ gid = fu_get_gid(group)
1916
+ list.each do |path|
1917
+ Entry_.new(path).chown uid, gid
1918
+ end
1919
+ end
1920
+ module_function :chown
1921
+
1922
+ # Like Bundler::FileUtils.chown, but changes owner and group recursively.
1923
+ #
1924
+ def chown_R(user, group, list, noop: nil, verbose: nil, force: nil)
1925
+ list = fu_list(list)
1926
+ fu_output_message sprintf('chown -R%s %s %s',
1927
+ (force ? 'f' : ''),
1928
+ (group ? "#{user}:#{group}" : user || ':'),
1929
+ list.join(' ')) if verbose
1930
+ return if noop
1931
+ uid = fu_get_uid(user)
1932
+ gid = fu_get_gid(group)
1933
+ list.each do |root|
1934
+ Entry_.new(root).traverse do |ent|
1935
+ begin
1936
+ ent.chown uid, gid
1937
+ rescue
1938
+ raise unless force
1939
+ end
1940
+ end
1941
+ end
1942
+ end
1943
+ module_function :chown_R
1944
+
1945
+ def fu_get_uid(user) #:nodoc:
1946
+ return nil unless user
1947
+ case user
1948
+ when Integer
1949
+ user
1950
+ when /\A\d+\z/
1951
+ user.to_i
1952
+ else
1953
+ require 'etc'
1954
+ Etc.getpwnam(user) ? Etc.getpwnam(user).uid : nil
1955
+ end
1956
+ end
1957
+ private_module_function :fu_get_uid
1958
+
1959
+ def fu_get_gid(group) #:nodoc:
1960
+ return nil unless group
1961
+ case group
1962
+ when Integer
1963
+ group
1964
+ when /\A\d+\z/
1965
+ group.to_i
1966
+ else
1967
+ require 'etc'
1968
+ Etc.getgrnam(group) ? Etc.getgrnam(group).gid : nil
1969
+ end
1970
+ end
1971
+ private_module_function :fu_get_gid
1972
+
1973
+ # Updates modification times (mtime) and access times (atime)
1974
+ # of the entries given by the paths in +list+
1975
+ # (a single path or an array of paths);
1976
+ # returns +list+ if it is an array, <tt>[list]</tt> otherwise.
1977
+ #
1978
+ # By default, creates an empty file for any path to a non-existent entry;
1979
+ # use keyword argument +nocreate+ to raise an exception instead.
1980
+ #
1981
+ # Argument +list+ or its elements
1982
+ # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
1983
+ #
1984
+ # Examples:
1985
+ #
1986
+ # # Single path.
1987
+ # f = File.new('src0.txt') # Existing file.
1988
+ # f.atime # => 2022-06-10 11:11:21.200277 -0700
1989
+ # f.mtime # => 2022-06-10 11:11:21.200277 -0700
1990
+ # Bundler::FileUtils.touch('src0.txt')
1991
+ # f = File.new('src0.txt')
1992
+ # f.atime # => 2022-06-11 08:28:09.8185343 -0700
1993
+ # f.mtime # => 2022-06-11 08:28:09.8185343 -0700
1994
+ #
1995
+ # # Array of paths.
1996
+ # Bundler::FileUtils.touch(['src0.txt', 'src0.dat'])
1997
+ #
1998
+ # Keyword arguments:
1999
+ #
2000
+ # - <tt>mtime: <i>time</i></tt> - sets the entry's mtime to the given time,
2001
+ # instead of the current time.
2002
+ # - <tt>nocreate: true</tt> - raises an exception if the entry does not exist.
2003
+ # - <tt>noop: true</tt> - does not touch entries; returns +nil+.
2004
+ # - <tt>verbose: true</tt> - prints an equivalent command:
2005
+ #
2006
+ # Bundler::FileUtils.touch('src0.txt', noop: true, verbose: true)
2007
+ # Bundler::FileUtils.touch(['src0.txt', 'src0.dat'], noop: true, verbose: true)
2008
+ # Bundler::FileUtils.touch(path, noop: true, verbose: true)
2009
+ #
2010
+ # Output:
2011
+ #
2012
+ # touch src0.txt
2013
+ # touch src0.txt src0.dat
2014
+ # touch src0.txt
2015
+ #
2016
+ # Related: Bundler::FileUtils.uptodate?.
2017
+ #
2018
+ def touch(list, noop: nil, verbose: nil, mtime: nil, nocreate: nil)
2019
+ list = fu_list(list)
2020
+ t = mtime
2021
+ if verbose
2022
+ fu_output_message "touch #{nocreate ? '-c ' : ''}#{t ? t.strftime('-t %Y%m%d%H%M.%S ') : ''}#{list.join ' '}"
2023
+ end
2024
+ return if noop
2025
+ list.each do |path|
2026
+ created = nocreate
2027
+ begin
2028
+ File.utime(t, t, path)
2029
+ rescue Errno::ENOENT
2030
+ raise if created
2031
+ File.open(path, 'a') {
2032
+ ;
2033
+ }
2034
+ created = true
2035
+ retry if t
2036
+ end
2037
+ end
2038
+ end
2039
+ module_function :touch
2040
+
2041
+ private
2042
+
2043
+ module StreamUtils_
2044
+ private
2045
+
2046
+ case (defined?(::RbConfig) ? ::RbConfig::CONFIG['host_os'] : ::RUBY_PLATFORM)
2047
+ when /mswin|mingw/
2048
+ def fu_windows?; true end
2049
+ else
2050
+ def fu_windows?; false end
2051
+ end
2052
+
2053
+ def fu_copy_stream0(src, dest, blksize = nil) #:nodoc:
2054
+ IO.copy_stream(src, dest)
2055
+ end
2056
+
2057
+ def fu_stream_blksize(*streams)
2058
+ streams.each do |s|
2059
+ next unless s.respond_to?(:stat)
2060
+ size = fu_blksize(s.stat)
2061
+ return size if size
2062
+ end
2063
+ fu_default_blksize()
2064
+ end
2065
+
2066
+ def fu_blksize(st)
2067
+ s = st.blksize
2068
+ return nil unless s
2069
+ return nil if s == 0
2070
+ s
2071
+ end
2072
+
2073
+ def fu_default_blksize
2074
+ 1024
2075
+ end
2076
+ end
2077
+
2078
+ include StreamUtils_
2079
+ extend StreamUtils_
2080
+
2081
+ class Entry_ #:nodoc: internal use only
2082
+ include StreamUtils_
2083
+
2084
+ def initialize(a, b = nil, deref = false)
2085
+ @prefix = @rel = @path = nil
2086
+ if b
2087
+ @prefix = a
2088
+ @rel = b
2089
+ else
2090
+ @path = a
2091
+ end
2092
+ @deref = deref
2093
+ @stat = nil
2094
+ @lstat = nil
2095
+ end
2096
+
2097
+ def inspect
2098
+ "\#<#{self.class} #{path()}>"
2099
+ end
2100
+
2101
+ def path
2102
+ if @path
2103
+ File.path(@path)
2104
+ else
2105
+ join(@prefix, @rel)
2106
+ end
2107
+ end
2108
+
2109
+ def prefix
2110
+ @prefix || @path
2111
+ end
2112
+
2113
+ def rel
2114
+ @rel
2115
+ end
2116
+
2117
+ def dereference?
2118
+ @deref
2119
+ end
2120
+
2121
+ def exist?
2122
+ begin
2123
+ lstat
2124
+ true
2125
+ rescue Errno::ENOENT
2126
+ false
2127
+ end
2128
+ end
2129
+
2130
+ def file?
2131
+ s = lstat!
2132
+ s and s.file?
2133
+ end
2134
+
2135
+ def directory?
2136
+ s = lstat!
2137
+ s and s.directory?
2138
+ end
2139
+
2140
+ def symlink?
2141
+ s = lstat!
2142
+ s and s.symlink?
2143
+ end
2144
+
2145
+ def chardev?
2146
+ s = lstat!
2147
+ s and s.chardev?
2148
+ end
2149
+
2150
+ def blockdev?
2151
+ s = lstat!
2152
+ s and s.blockdev?
2153
+ end
2154
+
2155
+ def socket?
2156
+ s = lstat!
2157
+ s and s.socket?
2158
+ end
2159
+
2160
+ def pipe?
2161
+ s = lstat!
2162
+ s and s.pipe?
2163
+ end
2164
+
2165
+ S_IF_DOOR = 0xD000
2166
+
2167
+ def door?
2168
+ s = lstat!
2169
+ s and (s.mode & 0xF000 == S_IF_DOOR)
2170
+ end
2171
+
2172
+ def entries
2173
+ opts = {}
2174
+ opts[:encoding] = fu_windows? ? ::Encoding::UTF_8 : path.encoding
2175
+
2176
+ files = Dir.children(path, **opts)
2177
+
2178
+ untaint = RUBY_VERSION < '2.7'
2179
+ files.map {|n| Entry_.new(prefix(), join(rel(), untaint ? n.untaint : n)) }
2180
+ end
2181
+
2182
+ def stat
2183
+ return @stat if @stat
2184
+ if lstat() and lstat().symlink?
2185
+ @stat = File.stat(path())
2186
+ else
2187
+ @stat = lstat()
2188
+ end
2189
+ @stat
2190
+ end
2191
+
2192
+ def stat!
2193
+ return @stat if @stat
2194
+ if lstat! and lstat!.symlink?
2195
+ @stat = File.stat(path())
2196
+ else
2197
+ @stat = lstat!
2198
+ end
2199
+ @stat
2200
+ rescue SystemCallError
2201
+ nil
2202
+ end
2203
+
2204
+ def lstat
2205
+ if dereference?
2206
+ @lstat ||= File.stat(path())
2207
+ else
2208
+ @lstat ||= File.lstat(path())
2209
+ end
2210
+ end
2211
+
2212
+ def lstat!
2213
+ lstat()
2214
+ rescue SystemCallError
2215
+ nil
2216
+ end
2217
+
2218
+ def chmod(mode)
2219
+ if symlink?
2220
+ File.lchmod mode, path() if have_lchmod?
2221
+ else
2222
+ File.chmod mode, path()
2223
+ end
2224
+ rescue Errno::EOPNOTSUPP
2225
+ end
2226
+
2227
+ def chown(uid, gid)
2228
+ if symlink?
2229
+ File.lchown uid, gid, path() if have_lchown?
2230
+ else
2231
+ File.chown uid, gid, path()
2232
+ end
2233
+ end
2234
+
2235
+ def link(dest)
2236
+ case
2237
+ when directory?
2238
+ if !File.exist?(dest) and descendant_directory?(dest, path)
2239
+ raise ArgumentError, "cannot link directory %s to itself %s" % [path, dest]
2240
+ end
2241
+ begin
2242
+ Dir.mkdir dest
2243
+ rescue
2244
+ raise unless File.directory?(dest)
2245
+ end
2246
+ else
2247
+ File.link path(), dest
2248
+ end
2249
+ end
2250
+
2251
+ def copy(dest)
2252
+ lstat
2253
+ case
2254
+ when file?
2255
+ copy_file dest
2256
+ when directory?
2257
+ if !File.exist?(dest) and descendant_directory?(dest, path)
2258
+ raise ArgumentError, "cannot copy directory %s to itself %s" % [path, dest]
2259
+ end
2260
+ begin
2261
+ Dir.mkdir dest
2262
+ rescue
2263
+ raise unless File.directory?(dest)
2264
+ end
2265
+ when symlink?
2266
+ File.symlink File.readlink(path()), dest
2267
+ when chardev?, blockdev?
2268
+ raise "cannot handle device file"
2269
+ when socket?
2270
+ begin
2271
+ require 'socket'
2272
+ rescue LoadError
2273
+ raise "cannot handle socket"
2274
+ else
2275
+ raise "cannot handle socket" unless defined?(UNIXServer)
2276
+ end
2277
+ UNIXServer.new(dest).close
2278
+ File.chmod lstat().mode, dest
2279
+ when pipe?
2280
+ raise "cannot handle FIFO" unless File.respond_to?(:mkfifo)
2281
+ File.mkfifo dest, lstat().mode
2282
+ when door?
2283
+ raise "cannot handle door: #{path()}"
2284
+ else
2285
+ raise "unknown file type: #{path()}"
2286
+ end
2287
+ end
2288
+
2289
+ def copy_file(dest)
2290
+ File.open(path()) do |s|
2291
+ File.open(dest, 'wb', s.stat.mode) do |f|
2292
+ IO.copy_stream(s, f)
2293
+ end
2294
+ end
2295
+ end
2296
+
2297
+ def copy_metadata(path)
2298
+ st = lstat()
2299
+ if !st.symlink?
2300
+ File.utime st.atime, st.mtime, path
2301
+ end
2302
+ mode = st.mode
2303
+ begin
2304
+ if st.symlink?
2305
+ begin
2306
+ File.lchown st.uid, st.gid, path
2307
+ rescue NotImplementedError
2308
+ end
2309
+ else
2310
+ File.chown st.uid, st.gid, path
2311
+ end
2312
+ rescue Errno::EPERM, Errno::EACCES
2313
+ # clear setuid/setgid
2314
+ mode &= 01777
2315
+ end
2316
+ if st.symlink?
2317
+ begin
2318
+ File.lchmod mode, path
2319
+ rescue NotImplementedError, Errno::EOPNOTSUPP
2320
+ end
2321
+ else
2322
+ File.chmod mode, path
2323
+ end
2324
+ end
2325
+
2326
+ def remove
2327
+ if directory?
2328
+ remove_dir1
2329
+ else
2330
+ remove_file
2331
+ end
2332
+ end
2333
+
2334
+ def remove_dir1
2335
+ platform_support {
2336
+ Dir.rmdir path().chomp(?/)
2337
+ }
2338
+ end
2339
+
2340
+ def remove_file
2341
+ platform_support {
2342
+ File.unlink path
2343
+ }
2344
+ end
2345
+
2346
+ def platform_support
2347
+ return yield unless fu_windows?
2348
+ first_time_p = true
2349
+ begin
2350
+ yield
2351
+ rescue Errno::ENOENT
2352
+ raise
2353
+ rescue => err
2354
+ if first_time_p
2355
+ first_time_p = false
2356
+ begin
2357
+ File.chmod 0700, path() # Windows does not have symlink
2358
+ retry
2359
+ rescue SystemCallError
2360
+ end
2361
+ end
2362
+ raise err
2363
+ end
2364
+ end
2365
+
2366
+ def preorder_traverse
2367
+ stack = [self]
2368
+ while ent = stack.pop
2369
+ yield ent
2370
+ stack.concat ent.entries.reverse if ent.directory?
2371
+ end
2372
+ end
2373
+
2374
+ alias traverse preorder_traverse
2375
+
2376
+ def postorder_traverse
2377
+ if directory?
2378
+ begin
2379
+ children = entries()
2380
+ rescue Errno::EACCES
2381
+ # Failed to get the list of children.
2382
+ # Assuming there is no children, try to process the parent directory.
2383
+ yield self
2384
+ return
2385
+ end
2386
+
2387
+ children.each do |ent|
2388
+ ent.postorder_traverse do |e|
2389
+ yield e
2390
+ end
2391
+ end
2392
+ end
2393
+ yield self
2394
+ end
2395
+
2396
+ def wrap_traverse(pre, post)
2397
+ pre.call self
2398
+ if directory?
2399
+ entries.each do |ent|
2400
+ ent.wrap_traverse pre, post
2401
+ end
2402
+ end
2403
+ post.call self
2404
+ end
2405
+
2406
+ private
2407
+
2408
+ @@fileutils_rb_have_lchmod = nil
2409
+
2410
+ def have_lchmod?
2411
+ # This is not MT-safe, but it does not matter.
2412
+ if @@fileutils_rb_have_lchmod == nil
2413
+ @@fileutils_rb_have_lchmod = check_have_lchmod?
2414
+ end
2415
+ @@fileutils_rb_have_lchmod
2416
+ end
2417
+
2418
+ def check_have_lchmod?
2419
+ return false unless File.respond_to?(:lchmod)
2420
+ File.lchmod 0
2421
+ return true
2422
+ rescue NotImplementedError
2423
+ return false
2424
+ end
2425
+
2426
+ @@fileutils_rb_have_lchown = nil
2427
+
2428
+ def have_lchown?
2429
+ # This is not MT-safe, but it does not matter.
2430
+ if @@fileutils_rb_have_lchown == nil
2431
+ @@fileutils_rb_have_lchown = check_have_lchown?
2432
+ end
2433
+ @@fileutils_rb_have_lchown
2434
+ end
2435
+
2436
+ def check_have_lchown?
2437
+ return false unless File.respond_to?(:lchown)
2438
+ File.lchown nil, nil
2439
+ return true
2440
+ rescue NotImplementedError
2441
+ return false
2442
+ end
2443
+
2444
+ def join(dir, base)
2445
+ return File.path(dir) if not base or base == '.'
2446
+ return File.path(base) if not dir or dir == '.'
2447
+ begin
2448
+ File.join(dir, base)
2449
+ rescue EncodingError
2450
+ if fu_windows?
2451
+ File.join(dir.encode(::Encoding::UTF_8), base.encode(::Encoding::UTF_8))
2452
+ else
2453
+ raise
2454
+ end
2455
+ end
2456
+ end
2457
+
2458
+ if File::ALT_SEPARATOR
2459
+ DIRECTORY_TERM = "(?=[/#{Regexp.quote(File::ALT_SEPARATOR)}]|\\z)"
2460
+ else
2461
+ DIRECTORY_TERM = "(?=/|\\z)"
2462
+ end
2463
+
2464
+ def descendant_directory?(descendant, ascendant)
2465
+ if File::FNM_SYSCASE.nonzero?
2466
+ File.expand_path(File.dirname(descendant)).casecmp(File.expand_path(ascendant)) == 0
2467
+ else
2468
+ File.expand_path(File.dirname(descendant)) == File.expand_path(ascendant)
2469
+ end
2470
+ end
2471
+ end # class Entry_
2472
+
2473
+ def fu_list(arg) #:nodoc:
2474
+ [arg].flatten.map {|path| File.path(path) }
2475
+ end
2476
+ private_module_function :fu_list
2477
+
2478
+ def fu_each_src_dest(src, dest) #:nodoc:
2479
+ fu_each_src_dest0(src, dest) do |s, d|
2480
+ raise ArgumentError, "same file: #{s} and #{d}" if fu_same?(s, d)
2481
+ yield s, d
2482
+ end
2483
+ end
2484
+ private_module_function :fu_each_src_dest
2485
+
2486
+ def fu_each_src_dest0(src, dest, target_directory = true) #:nodoc:
2487
+ if tmp = Array.try_convert(src)
2488
+ tmp.each do |s|
2489
+ s = File.path(s)
2490
+ yield s, (target_directory ? File.join(dest, File.basename(s)) : dest)
2491
+ end
2492
+ else
2493
+ src = File.path(src)
2494
+ if target_directory and File.directory?(dest)
2495
+ yield src, File.join(dest, File.basename(src))
2496
+ else
2497
+ yield src, File.path(dest)
2498
+ end
2499
+ end
2500
+ end
2501
+ private_module_function :fu_each_src_dest0
2502
+
2503
+ def fu_same?(a, b) #:nodoc:
2504
+ File.identical?(a, b)
2505
+ end
2506
+ private_module_function :fu_same?
2507
+
2508
+ def fu_output_message(msg) #:nodoc:
2509
+ output = @fileutils_output if defined?(@fileutils_output)
2510
+ output ||= $stdout
2511
+ if defined?(@fileutils_label)
2512
+ msg = @fileutils_label + msg
2513
+ end
2514
+ output.puts msg
2515
+ end
2516
+ private_module_function :fu_output_message
2517
+
2518
+ def fu_split_path(path)
2519
+ path = File.path(path)
2520
+ list = []
2521
+ until (parent, base = File.split(path); parent == path or parent == ".")
2522
+ list << base
2523
+ path = parent
2524
+ end
2525
+ list << path
2526
+ list.reverse!
2527
+ end
2528
+ private_module_function :fu_split_path
2529
+
2530
+ def fu_relative_components_from(target, base) #:nodoc:
2531
+ i = 0
2532
+ while target[i]&.== base[i]
2533
+ i += 1
2534
+ end
2535
+ Array.new(base.size-i, '..').concat(target[i..-1])
2536
+ end
2537
+ private_module_function :fu_relative_components_from
2538
+
2539
+ def fu_clean_components(*comp)
2540
+ comp.shift while comp.first == "."
2541
+ return comp if comp.empty?
2542
+ clean = [comp.shift]
2543
+ path = File.join(*clean, "") # ending with File::SEPARATOR
2544
+ while c = comp.shift
2545
+ if c == ".." and clean.last != ".." and !(fu_have_symlink? && File.symlink?(path))
2546
+ clean.pop
2547
+ path.chomp!(%r((?<=\A|/)[^/]+/\z), "")
2548
+ else
2549
+ clean << c
2550
+ path << c << "/"
2551
+ end
2552
+ end
2553
+ clean
2554
+ end
2555
+ private_module_function :fu_clean_components
2556
+
2557
+ if fu_windows?
2558
+ def fu_starting_path?(path)
2559
+ path&.start_with?(%r(\w:|/))
2560
+ end
2561
+ else
2562
+ def fu_starting_path?(path)
2563
+ path&.start_with?("/")
2564
+ end
2565
+ end
2566
+ private_module_function :fu_starting_path?
2567
+
2568
+ # This hash table holds command options.
2569
+ OPT_TABLE = {} #:nodoc: internal use only
2570
+ (private_instance_methods & methods(false)).inject(OPT_TABLE) {|tbl, name|
2571
+ (tbl[name.to_s] = instance_method(name).parameters).map! {|t, n| n if t == :key}.compact!
2572
+ tbl
2573
+ }
2574
+
2575
+ public
2576
+
2577
+ # Returns an array of the string names of \Bundler::FileUtils methods
2578
+ # that accept one or more keyword arguments:
2579
+ #
2580
+ # Bundler::FileUtils.commands.sort.take(3) # => ["cd", "chdir", "chmod"]
2581
+ #
2582
+ def self.commands
2583
+ OPT_TABLE.keys
2584
+ end
2585
+
2586
+ # Returns an array of the string keyword names:
2587
+ #
2588
+ # Bundler::FileUtils.options.take(3) # => ["noop", "verbose", "force"]
2589
+ #
2590
+ def self.options
2591
+ OPT_TABLE.values.flatten.uniq.map {|sym| sym.to_s }
2592
+ end
2593
+
2594
+ # Returns +true+ if method +mid+ accepts the given option +opt+, +false+ otherwise;
2595
+ # the arguments may be strings or symbols:
2596
+ #
2597
+ # Bundler::FileUtils.have_option?(:chmod, :noop) # => true
2598
+ # Bundler::FileUtils.have_option?('chmod', 'secure') # => false
2599
+ #
2600
+ def self.have_option?(mid, opt)
2601
+ li = OPT_TABLE[mid.to_s] or raise ArgumentError, "no such method: #{mid}"
2602
+ li.include?(opt)
2603
+ end
2604
+
2605
+ # Returns an array of the string keyword name for method +mid+;
2606
+ # the argument may be a string or a symbol:
2607
+ #
2608
+ # Bundler::FileUtils.options_of(:rm) # => ["force", "noop", "verbose"]
2609
+ # Bundler::FileUtils.options_of('mv') # => ["force", "noop", "verbose", "secure"]
2610
+ #
2611
+ def self.options_of(mid)
2612
+ OPT_TABLE[mid.to_s].map {|sym| sym.to_s }
2613
+ end
2614
+
2615
+ # Returns an array of the string method names of the methods
2616
+ # that accept the given keyword option +opt+;
2617
+ # the argument must be a symbol:
2618
+ #
2619
+ # Bundler::FileUtils.collect_method(:preserve) # => ["cp", "copy", "cp_r", "install"]
2620
+ #
2621
+ def self.collect_method(opt)
2622
+ OPT_TABLE.keys.select {|m| OPT_TABLE[m].include?(opt) }
2623
+ end
2624
+
2625
+ private
2626
+
2627
+ LOW_METHODS = singleton_methods(false) - collect_method(:noop).map(&:intern) # :nodoc:
2628
+ module LowMethods # :nodoc: internal use only
2629
+ private
2630
+ def _do_nothing(*)end
2631
+ ::Bundler::FileUtils::LOW_METHODS.map {|name| alias_method name, :_do_nothing}
2632
+ end
2633
+
2634
+ METHODS = singleton_methods() - [:private_module_function, # :nodoc:
2635
+ :commands, :options, :have_option?, :options_of, :collect_method]
2636
+
2637
+ #
2638
+ # This module has all methods of Bundler::FileUtils module, but it outputs messages
2639
+ # before acting. This equates to passing the <tt>:verbose</tt> flag to
2640
+ # methods in Bundler::FileUtils.
2641
+ #
2642
+ module Verbose
2643
+ include Bundler::FileUtils
2644
+ names = ::Bundler::FileUtils.collect_method(:verbose)
2645
+ names.each do |name|
2646
+ module_eval(<<-EOS, __FILE__, __LINE__ + 1)
2647
+ def #{name}(*args, **options)
2648
+ super(*args, **options, verbose: true)
2649
+ end
2650
+ EOS
2651
+ end
2652
+ private(*names)
2653
+ extend self
2654
+ class << self
2655
+ public(*::Bundler::FileUtils::METHODS)
2656
+ end
2657
+ end
2658
+
2659
+ #
2660
+ # This module has all methods of Bundler::FileUtils module, but never changes
2661
+ # files/directories. This equates to passing the <tt>:noop</tt> flag
2662
+ # to methods in Bundler::FileUtils.
2663
+ #
2664
+ module NoWrite
2665
+ include Bundler::FileUtils
2666
+ include LowMethods
2667
+ names = ::Bundler::FileUtils.collect_method(:noop)
2668
+ names.each do |name|
2669
+ module_eval(<<-EOS, __FILE__, __LINE__ + 1)
2670
+ def #{name}(*args, **options)
2671
+ super(*args, **options, noop: true)
2672
+ end
2673
+ EOS
2674
+ end
2675
+ private(*names)
2676
+ extend self
2677
+ class << self
2678
+ public(*::Bundler::FileUtils::METHODS)
2679
+ end
2680
+ end
2681
+
2682
+ #
2683
+ # This module has all methods of Bundler::FileUtils module, but never changes
2684
+ # files/directories, with printing message before acting.
2685
+ # This equates to passing the <tt>:noop</tt> and <tt>:verbose</tt> flag
2686
+ # to methods in Bundler::FileUtils.
2687
+ #
2688
+ module DryRun
2689
+ include Bundler::FileUtils
2690
+ include LowMethods
2691
+ names = ::Bundler::FileUtils.collect_method(:noop)
2692
+ names.each do |name|
2693
+ module_eval(<<-EOS, __FILE__, __LINE__ + 1)
2694
+ def #{name}(*args, **options)
2695
+ super(*args, **options, noop: true, verbose: true)
2696
+ end
2697
+ EOS
2698
+ end
2699
+ private(*names)
2700
+ extend self
2701
+ class << self
2702
+ public(*::Bundler::FileUtils::METHODS)
2703
+ end
2704
+ end
2705
+
2706
+ end