@blazetrails/ruby-compat 0.0.0-stage → 0.1.0-alpha0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/NOTICE +6 -0
- package/README.md +440 -2
- package/dist/argument-error.d.ts +15 -0
- package/dist/argument-error.js +15 -0
- package/dist/argument-error.js.map +1 -0
- package/dist/array.d.ts +415 -0
- package/dist/array.js +1330 -0
- package/dist/array.js.map +1 -0
- package/dist/async-context-adapter.d.ts +19 -0
- package/dist/async-context-adapter.js +139 -0
- package/dist/async-context-adapter.js.map +1 -0
- package/dist/backtrace-location.d.ts +78 -0
- package/dist/backtrace-location.js +158 -0
- package/dist/backtrace-location.js.map +1 -0
- package/dist/base64.d.ts +73 -0
- package/dist/base64.js +164 -0
- package/dist/base64.js.map +1 -0
- package/dist/benchmark.d.ts +19 -0
- package/dist/benchmark.js +16 -0
- package/dist/benchmark.js.map +1 -0
- package/dist/big-decimal.d.ts +111 -0
- package/dist/big-decimal.js +584 -0
- package/dist/big-decimal.js.map +1 -0
- package/dist/bundler.d.ts +44 -0
- package/dist/bundler.js +97 -0
- package/dist/bundler.js.map +1 -0
- package/dist/cgi.d.ts +89 -0
- package/dist/cgi.js +168 -0
- package/dist/cgi.js.map +1 -0
- package/dist/child-process-adapter.d.ts +110 -0
- package/dist/child-process-adapter.js +272 -0
- package/dist/child-process-adapter.js.map +1 -0
- package/dist/class-module.d.ts +10 -0
- package/dist/class-module.js +10 -0
- package/dist/class-module.js.map +1 -0
- package/dist/classpath.d.ts +93 -0
- package/dist/classpath.js +210 -0
- package/dist/classpath.js.map +1 -0
- package/dist/closed-queue-error.d.ts +10 -0
- package/dist/closed-queue-error.js +10 -0
- package/dist/closed-queue-error.js.map +1 -0
- package/dist/comparable.d.ts +127 -0
- package/dist/comparable.js +376 -0
- package/dist/comparable.js.map +1 -0
- package/dist/complex.d.ts +49 -0
- package/dist/complex.js +164 -0
- package/dist/complex.js.map +1 -0
- package/dist/concurrent/atomic-boolean.d.ts +24 -0
- package/dist/concurrent/atomic-boolean.js +43 -0
- package/dist/concurrent/atomic-boolean.js.map +1 -0
- package/dist/concurrent/atomic-fixnum.d.ts +21 -0
- package/dist/concurrent/atomic-fixnum.js +35 -0
- package/dist/concurrent/atomic-fixnum.js.map +1 -0
- package/dist/concurrent/count-down-latch.d.ts +20 -0
- package/dist/concurrent/count-down-latch.js +50 -0
- package/dist/concurrent/count-down-latch.js.map +1 -0
- package/dist/concurrent/cyclic-barrier.d.ts +18 -0
- package/dist/concurrent/cyclic-barrier.js +50 -0
- package/dist/concurrent/cyclic-barrier.js.map +1 -0
- package/dist/concurrent/event.d.ts +19 -0
- package/dist/concurrent/event.js +31 -0
- package/dist/concurrent/event.js.map +1 -0
- package/dist/concurrent/map.d.ts +149 -0
- package/dist/concurrent/map.js +202 -0
- package/dist/concurrent/map.js.map +1 -0
- package/dist/concurrent/read-write-lock.d.ts +25 -0
- package/dist/concurrent/read-write-lock.js +70 -0
- package/dist/concurrent/read-write-lock.js.map +1 -0
- package/dist/concurrent/semaphore.d.ts +24 -0
- package/dist/concurrent/semaphore.js +74 -0
- package/dist/concurrent/semaphore.js.map +1 -0
- package/dist/concurrent/timer-task.d.ts +52 -0
- package/dist/concurrent/timer-task.js +112 -0
- package/dist/concurrent/timer-task.js.map +1 -0
- package/dist/constants.generated.d.ts +2 -0
- package/dist/constants.generated.js +64 -0
- package/dist/constants.generated.js.map +1 -0
- package/dist/converter-not-found-error.d.ts +14 -0
- package/dist/converter-not-found-error.js +14 -0
- package/dist/converter-not-found-error.js.map +1 -0
- package/dist/crypto-adapter.d.ts +64 -0
- package/dist/crypto-adapter.js +365 -0
- package/dist/crypto-adapter.js.map +1 -0
- package/dist/delegate.d.ts +156 -0
- package/dist/delegate.js +306 -0
- package/dist/delegate.js.map +1 -0
- package/dist/digest.d.ts +99 -0
- package/dist/digest.js +131 -0
- package/dist/digest.js.map +1 -0
- package/dist/dir.d.ts +225 -0
- package/dist/dir.js +608 -0
- package/dist/dir.js.map +1 -0
- package/dist/encoding-error.d.ts +14 -0
- package/dist/encoding-error.js +17 -0
- package/dist/encoding-error.js.map +1 -0
- package/dist/encoding.d.ts +121 -0
- package/dist/encoding.js +306 -0
- package/dist/encoding.js.map +1 -0
- package/dist/ensure.d.ts +15 -0
- package/dist/ensure.js +35 -0
- package/dist/ensure.js.map +1 -0
- package/dist/enumerable.d.ts +375 -0
- package/dist/enumerable.js +1102 -0
- package/dist/enumerable.js.map +1 -0
- package/dist/enumerator.d.ts +324 -0
- package/dist/enumerator.js +625 -0
- package/dist/enumerator.js.map +1 -0
- package/dist/eof-error.d.ts +14 -0
- package/dist/eof-error.js +14 -0
- package/dist/eof-error.js.map +1 -0
- package/dist/errno.d.ts +447 -0
- package/dist/errno.js +616 -0
- package/dist/errno.js.map +1 -0
- package/dist/exc-detailed-message.d.ts +15 -0
- package/dist/exc-detailed-message.js +106 -0
- package/dist/exc-detailed-message.js.map +1 -0
- package/dist/exc-to-s.d.ts +10 -0
- package/dist/exc-to-s.js +21 -0
- package/dist/exc-to-s.js.map +1 -0
- package/dist/exception.d.ts +44 -0
- package/dist/exception.js +115 -0
- package/dist/exception.js.map +1 -0
- package/dist/fiber-error.d.ts +12 -0
- package/dist/fiber-error.js +12 -0
- package/dist/fiber-error.js.map +1 -0
- package/dist/fiber.d.ts +51 -0
- package/dist/fiber.js +178 -0
- package/dist/fiber.js.map +1 -0
- package/dist/file-utils.d.ts +480 -0
- package/dist/file-utils.js +1824 -0
- package/dist/file-utils.js.map +1 -0
- package/dist/file.d.ts +643 -0
- package/dist/file.js +1334 -0
- package/dist/file.js.map +1 -0
- package/dist/float-domain-error.d.ts +17 -0
- package/dist/float-domain-error.js +17 -0
- package/dist/float-domain-error.js.map +1 -0
- package/dist/fork-children.d.ts +23 -0
- package/dist/fork-children.js +32 -0
- package/dist/fork-children.js.map +1 -0
- package/dist/frozen-error.d.ts +33 -0
- package/dist/frozen-error.js +41 -0
- package/dist/frozen-error.js.map +1 -0
- package/dist/fs-adapter.d.ts +158 -0
- package/dist/fs-adapter.js +253 -0
- package/dist/fs-adapter.js.map +1 -0
- package/dist/gem/deprecate.d.ts +10 -0
- package/dist/gem/deprecate.js +8 -0
- package/dist/gem/deprecate.js.map +1 -0
- package/dist/gem/requirement.d.ts +55 -0
- package/dist/gem/requirement.js +91 -0
- package/dist/gem/requirement.js.map +1 -0
- package/dist/gem/version.d.ts +50 -0
- package/dist/gem/version.js +148 -0
- package/dist/gem/version.js.map +1 -0
- package/dist/gem.d.ts +59 -0
- package/dist/gem.js +82 -0
- package/dist/gem.js.map +1 -0
- package/dist/hash.d.ts +967 -0
- package/dist/hash.js +1572 -0
- package/dist/hash.js.map +1 -0
- package/dist/http-adapter.d.ts +124 -0
- package/dist/http-adapter.js +220 -0
- package/dist/http-adapter.js.map +1 -0
- package/dist/immediate-executor.d.ts +20 -0
- package/dist/immediate-executor.js +39 -0
- package/dist/immediate-executor.js.map +1 -0
- package/dist/include.d.ts +778 -0
- package/dist/include.js +2208 -0
- package/dist/include.js.map +1 -0
- package/dist/index-error.d.ts +13 -0
- package/dist/index-error.js +13 -0
- package/dist/index-error.js.map +1 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +166 -0
- package/dist/index.js.map +1 -0
- package/dist/invalid-byte-sequence-error.d.ts +62 -0
- package/dist/invalid-byte-sequence-error.js +75 -0
- package/dist/invalid-byte-sequence-error.js.map +1 -0
- package/dist/io-error.d.ts +14 -0
- package/dist/io-error.js +17 -0
- package/dist/io-error.js.map +1 -0
- package/dist/io.d.ts +867 -0
- package/dist/io.js +1960 -0
- package/dist/io.js.map +1 -0
- package/dist/ipaddr.d.ts +79 -0
- package/dist/ipaddr.js +405 -0
- package/dist/ipaddr.js.map +1 -0
- package/dist/json.d.ts +70 -0
- package/dist/json.js +181 -0
- package/dist/json.js.map +1 -0
- package/dist/kernel-catch.d.ts +59 -0
- package/dist/kernel-catch.js +184 -0
- package/dist/kernel-catch.js.map +1 -0
- package/dist/kernel-float.d.ts +19 -0
- package/dist/kernel-float.js +54 -0
- package/dist/kernel-float.js.map +1 -0
- package/dist/kernel-fork.d.ts +30 -0
- package/dist/kernel-fork.js +72 -0
- package/dist/kernel-fork.js.map +1 -0
- package/dist/kernel-format.d.ts +27 -0
- package/dist/kernel-format.js +901 -0
- package/dist/kernel-format.js.map +1 -0
- package/dist/kernel-hash.d.ts +7 -0
- package/dist/kernel-hash.js +33 -0
- package/dist/kernel-hash.js.map +1 -0
- package/dist/kernel-integer.d.ts +49 -0
- package/dist/kernel-integer.js +170 -0
- package/dist/kernel-integer.js.map +1 -0
- package/dist/kernel-rand.d.ts +16 -0
- package/dist/kernel-rand.js +237 -0
- package/dist/kernel-rand.js.map +1 -0
- package/dist/kernel-system.d.ts +39 -0
- package/dist/kernel-system.js +103 -0
- package/dist/kernel-system.js.map +1 -0
- package/dist/kernel-warn.d.ts +35 -0
- package/dist/kernel-warn.js +73 -0
- package/dist/kernel-warn.js.map +1 -0
- package/dist/key-error.d.ts +44 -0
- package/dist/key-error.js +59 -0
- package/dist/key-error.js.map +1 -0
- package/dist/keyword-splat.d.ts +41 -0
- package/dist/keyword-splat.js +65 -0
- package/dist/keyword-splat.js.map +1 -0
- package/dist/load-error.d.ts +19 -0
- package/dist/load-error.js +19 -0
- package/dist/load-error.js.map +1 -0
- package/dist/load.d.ts +128 -0
- package/dist/load.js +278 -0
- package/dist/load.js.map +1 -0
- package/dist/loaded-features.d.ts +13 -0
- package/dist/loaded-features.js +15 -0
- package/dist/loaded-features.js.map +1 -0
- package/dist/local-jump-error.d.ts +12 -0
- package/dist/local-jump-error.js +12 -0
- package/dist/local-jump-error.js.map +1 -0
- package/dist/logger/formatter.d.ts +21 -0
- package/dist/logger/formatter.js +43 -0
- package/dist/logger/formatter.js.map +1 -0
- package/dist/logger/log-device.d.ts +52 -0
- package/dist/logger/log-device.js +104 -0
- package/dist/logger/log-device.js.map +1 -0
- package/dist/logger/severity.d.ts +23 -0
- package/dist/logger/severity.js +42 -0
- package/dist/logger/severity.js.map +1 -0
- package/dist/logger.d.ts +127 -0
- package/dist/logger.js +218 -0
- package/dist/logger.js.map +1 -0
- package/dist/marshal.d.ts +83 -0
- package/dist/marshal.js +1487 -0
- package/dist/marshal.js.map +1 -0
- package/dist/match-data.d.ts +161 -0
- package/dist/match-data.js +284 -0
- package/dist/match-data.js.map +1 -0
- package/dist/method-cache.d.ts +81 -0
- package/dist/method-cache.js +109 -0
- package/dist/method-cache.js.map +1 -0
- package/dist/method-missing-proxy.d.ts +53 -0
- package/dist/method-missing-proxy.js +154 -0
- package/dist/method-missing-proxy.js.map +1 -0
- package/dist/method.d.ts +132 -0
- package/dist/method.js +320 -0
- package/dist/method.js.map +1 -0
- package/dist/monitor.d.ts +114 -0
- package/dist/monitor.js +270 -0
- package/dist/monitor.js.map +1 -0
- package/dist/mutex.d.ts +51 -0
- package/dist/mutex.js +150 -0
- package/dist/mutex.js.map +1 -0
- package/dist/name-error.d.ts +45 -0
- package/dist/name-error.js +54 -0
- package/dist/name-error.js.map +1 -0
- package/dist/net/http/exceptions.d.ts +31 -0
- package/dist/net/http/exceptions.js +46 -0
- package/dist/net/http/exceptions.js.map +1 -0
- package/dist/net/http/request.d.ts +137 -0
- package/dist/net/http/request.js +559 -0
- package/dist/net/http/request.js.map +1 -0
- package/dist/net/http/requests.d.ts +197 -0
- package/dist/net/http/requests.js +197 -0
- package/dist/net/http/requests.js.map +1 -0
- package/dist/net/http/response.d.ts +141 -0
- package/dist/net/http/response.js +416 -0
- package/dist/net/http/response.js.map +1 -0
- package/dist/net/http/responses.d.ts +345 -0
- package/dist/net/http/responses.js +486 -0
- package/dist/net/http/responses.js.map +1 -0
- package/dist/net/http.d.ts +278 -0
- package/dist/net/http.js +760 -0
- package/dist/net/http.js.map +1 -0
- package/dist/net/protocol.d.ts +227 -0
- package/dist/net/protocol.js +392 -0
- package/dist/net/protocol.js.map +1 -0
- package/dist/nil-class.d.ts +10 -0
- package/dist/nil-class.js +27 -0
- package/dist/nil-class.js.map +1 -0
- package/dist/no-method-error.d.ts +38 -0
- package/dist/no-method-error.js +45 -0
- package/dist/no-method-error.js.map +1 -0
- package/dist/not-implemented-error.d.ts +13 -0
- package/dist/not-implemented-error.js +13 -0
- package/dist/not-implemented-error.js.map +1 -0
- package/dist/numeric-class.d.ts +29 -0
- package/dist/numeric-class.js +41 -0
- package/dist/numeric-class.js.map +1 -0
- package/dist/numeric.d.ts +226 -0
- package/dist/numeric.js +848 -0
- package/dist/numeric.js.map +1 -0
- package/dist/object-space.d.ts +34 -0
- package/dist/object-space.js +152 -0
- package/dist/object-space.js.map +1 -0
- package/dist/object.d.ts +833 -0
- package/dist/object.js +2131 -0
- package/dist/object.js.map +1 -0
- package/dist/open-uri.d.ts +180 -0
- package/dist/open-uri.js +402 -0
- package/dist/open-uri.js.map +1 -0
- package/dist/open3.d.ts +69 -0
- package/dist/open3.js +134 -0
- package/dist/open3.js.map +1 -0
- package/dist/openssl.d.ts +479 -0
- package/dist/openssl.js +1052 -0
- package/dist/openssl.js.map +1 -0
- package/dist/optparse.d.ts +130 -0
- package/dist/optparse.js +457 -0
- package/dist/optparse.js.map +1 -0
- package/dist/os-adapter.d.ts +20 -0
- package/dist/os-adapter.js +95 -0
- package/dist/os-adapter.js.map +1 -0
- package/dist/pathname.d.ts +73 -0
- package/dist/pathname.js +412 -0
- package/dist/pathname.js.map +1 -0
- package/dist/pp.d.ts +60 -0
- package/dist/pp.js +195 -0
- package/dist/pp.js.map +1 -0
- package/dist/pretty-print.d.ts +89 -0
- package/dist/pretty-print.js +232 -0
- package/dist/pretty-print.js.map +1 -0
- package/dist/process-adapter.d.ts +229 -0
- package/dist/process-adapter.js +889 -0
- package/dist/process-adapter.js.map +1 -0
- package/dist/process.d.ts +202 -0
- package/dist/process.js +433 -0
- package/dist/process.js.map +1 -0
- package/dist/psych/class-loader.d.ts +92 -0
- package/dist/psych/class-loader.js +139 -0
- package/dist/psych/class-loader.js.map +1 -0
- package/dist/psych/coder.d.ts +144 -0
- package/dist/psych/coder.js +176 -0
- package/dist/psych/coder.js.map +1 -0
- package/dist/psych/core-ext.d.ts +8 -0
- package/dist/psych/core-ext.js +10 -0
- package/dist/psych/core-ext.js.map +1 -0
- package/dist/psych/emitter.d.ts +116 -0
- package/dist/psych/emitter.js +1130 -0
- package/dist/psych/emitter.js.map +1 -0
- package/dist/psych/exception.d.ts +43 -0
- package/dist/psych/exception.js +54 -0
- package/dist/psych/exception.js.map +1 -0
- package/dist/psych/handler.d.ts +59 -0
- package/dist/psych/handler.js +95 -0
- package/dist/psych/handler.js.map +1 -0
- package/dist/psych/handlers/document-stream.d.ts +17 -0
- package/dist/psych/handlers/document-stream.js +26 -0
- package/dist/psych/handlers/document-stream.js.map +1 -0
- package/dist/psych/nodes/alias.d.ts +15 -0
- package/dist/psych/nodes/alias.js +22 -0
- package/dist/psych/nodes/alias.js.map +1 -0
- package/dist/psych/nodes/document.d.ts +23 -0
- package/dist/psych/nodes/document.js +35 -0
- package/dist/psych/nodes/document.js.map +1 -0
- package/dist/psych/nodes/mapping.d.ts +25 -0
- package/dist/psych/nodes/mapping.js +35 -0
- package/dist/psych/nodes/mapping.js.map +1 -0
- package/dist/psych/nodes/node.d.ts +59 -0
- package/dist/psych/nodes/node.js +79 -0
- package/dist/psych/nodes/node.js.map +1 -0
- package/dist/psych/nodes/scalar.d.ts +35 -0
- package/dist/psych/nodes/scalar.js +47 -0
- package/dist/psych/nodes/scalar.js.map +1 -0
- package/dist/psych/nodes/sequence.d.ts +25 -0
- package/dist/psych/nodes/sequence.js +35 -0
- package/dist/psych/nodes/sequence.js.map +1 -0
- package/dist/psych/nodes/stream.d.ts +23 -0
- package/dist/psych/nodes/stream.js +31 -0
- package/dist/psych/nodes/stream.js.map +1 -0
- package/dist/psych/omap.d.ts +9 -0
- package/dist/psych/omap.js +9 -0
- package/dist/psych/omap.js.map +1 -0
- package/dist/psych/parser.d.ts +41 -0
- package/dist/psych/parser.js +139 -0
- package/dist/psych/parser.js.map +1 -0
- package/dist/psych/scalar-scanner.d.ts +31 -0
- package/dist/psych/scalar-scanner.js +169 -0
- package/dist/psych/scalar-scanner.js.map +1 -0
- package/dist/psych/syntax-error.d.ts +23 -0
- package/dist/psych/syntax-error.js +35 -0
- package/dist/psych/syntax-error.js.map +1 -0
- package/dist/psych/tree-builder.d.ts +51 -0
- package/dist/psych/tree-builder.js +118 -0
- package/dist/psych/tree-builder.js.map +1 -0
- package/dist/psych/visitors/depth-first.d.ts +27 -0
- package/dist/psych/visitors/depth-first.js +37 -0
- package/dist/psych/visitors/depth-first.js.map +1 -0
- package/dist/psych/visitors/emitter.d.ts +32 -0
- package/dist/psych/visitors/emitter.js +63 -0
- package/dist/psych/visitors/emitter.js.map +1 -0
- package/dist/psych/visitors/to-ruby.d.ts +110 -0
- package/dist/psych/visitors/to-ruby.js +396 -0
- package/dist/psych/visitors/to-ruby.js.map +1 -0
- package/dist/psych/visitors/visitor.d.ts +11 -0
- package/dist/psych/visitors/visitor.js +17 -0
- package/dist/psych/visitors/visitor.js.map +1 -0
- package/dist/psych/visitors/yaml-tree.d.ts +182 -0
- package/dist/psych/visitors/yaml-tree.js +593 -0
- package/dist/psych/visitors/yaml-tree.js.map +1 -0
- package/dist/psych-adapter.d.ts +65 -0
- package/dist/psych-adapter.js +121 -0
- package/dist/psych-adapter.js.map +1 -0
- package/dist/psych-yaml.d.ts +2 -0
- package/dist/psych-yaml.js +5 -0
- package/dist/psych-yaml.js.map +1 -0
- package/dist/psych.d.ts +257 -0
- package/dist/psych.js +332 -0
- package/dist/psych.js.map +1 -0
- package/dist/queue.d.ts +137 -0
- package/dist/queue.js +236 -0
- package/dist/queue.js.map +1 -0
- package/dist/racc/parser.d.ts +70 -0
- package/dist/racc/parser.js +206 -0
- package/dist/racc/parser.js.map +1 -0
- package/dist/range-error.d.ts +15 -0
- package/dist/range-error.js +15 -0
- package/dist/range-error.js.map +1 -0
- package/dist/range.d.ts +166 -0
- package/dist/range.js +421 -0
- package/dist/range.js.map +1 -0
- package/dist/rational.d.ts +168 -0
- package/dist/rational.js +587 -0
- package/dist/rational.js.map +1 -0
- package/dist/rb-config.d.ts +33 -0
- package/dist/rb-config.js +53 -0
- package/dist/rb-config.js.map +1 -0
- package/dist/rb-equal.d.ts +66 -0
- package/dist/rb-equal.js +262 -0
- package/dist/rb-equal.js.map +1 -0
- package/dist/rb-hash.d.ts +26 -0
- package/dist/rb-hash.js +108 -0
- package/dist/rb-hash.js.map +1 -0
- package/dist/regexp.d.ts +82 -0
- package/dist/regexp.js +191 -0
- package/dist/regexp.js.map +1 -0
- package/dist/repl-adapter.d.ts +270 -0
- package/dist/repl-adapter.js +562 -0
- package/dist/repl-adapter.js.map +1 -0
- package/dist/resolv.d.ts +30 -0
- package/dist/resolv.js +48 -0
- package/dist/resolv.js.map +1 -0
- package/dist/ruby-empty.d.ts +28 -0
- package/dist/ruby-empty.js +40 -0
- package/dist/ruby-empty.js.map +1 -0
- package/dist/ruby-platform.d.ts +39 -0
- package/dist/ruby-platform.js +49 -0
- package/dist/ruby-platform.js.map +1 -0
- package/dist/runtime-error.d.ts +15 -0
- package/dist/runtime-error.js +15 -0
- package/dist/runtime-error.js.map +1 -0
- package/dist/scheduled-task.d.ts +73 -0
- package/dist/scheduled-task.js +150 -0
- package/dist/scheduled-task.js.map +1 -0
- package/dist/secure-random.d.ts +50 -0
- package/dist/secure-random.js +141 -0
- package/dist/secure-random.js.map +1 -0
- package/dist/set.d.ts +158 -0
- package/dist/set.js +352 -0
- package/dist/set.js.map +1 -0
- package/dist/shellwords.d.ts +27 -0
- package/dist/shellwords.js +53 -0
- package/dist/shellwords.js.map +1 -0
- package/dist/signal-exception.d.ts +43 -0
- package/dist/signal-exception.js +88 -0
- package/dist/signal-exception.js.map +1 -0
- package/dist/socket.d.ts +230 -0
- package/dist/socket.js +484 -0
- package/dist/socket.js.map +1 -0
- package/dist/standard-error.d.ts +27 -0
- package/dist/standard-error.js +49 -0
- package/dist/standard-error.js.map +1 -0
- package/dist/stop-iteration.d.ts +10 -0
- package/dist/stop-iteration.js +10 -0
- package/dist/stop-iteration.js.map +1 -0
- package/dist/string/b.d.ts +19 -0
- package/dist/string/b.js +28 -0
- package/dist/string/b.js.map +1 -0
- package/dist/string/byte-methods.d.ts +57 -0
- package/dist/string/byte-methods.js +266 -0
- package/dist/string/byte-methods.js.map +1 -0
- package/dist/string/bytes.d.ts +35 -0
- package/dist/string/bytes.js +123 -0
- package/dist/string/bytes.js.map +1 -0
- package/dist/string/case-mapping.d.ts +57 -0
- package/dist/string/case-mapping.js +192 -0
- package/dist/string/case-mapping.js.map +1 -0
- package/dist/string/chomp.d.ts +15 -0
- package/dist/string/chomp.js +32 -0
- package/dist/string/chomp.js.map +1 -0
- package/dist/string/convert.d.ts +55 -0
- package/dist/string/convert.js +316 -0
- package/dist/string/convert.js.map +1 -0
- package/dist/string/delete.d.ts +14 -0
- package/dist/string/delete.js +17 -0
- package/dist/string/delete.js.map +1 -0
- package/dist/string/each.d.ts +108 -0
- package/dist/string/each.js +305 -0
- package/dist/string/each.js.map +1 -0
- package/dist/string/encode.d.ts +37 -0
- package/dist/string/encode.js +268 -0
- package/dist/string/encode.js.map +1 -0
- package/dist/string/force-encoding.d.ts +72 -0
- package/dist/string/force-encoding.js +147 -0
- package/dist/string/force-encoding.js.map +1 -0
- package/dist/string/inspect.d.ts +17 -0
- package/dist/string/inspect.js +81 -0
- package/dist/string/inspect.js.map +1 -0
- package/dist/string/method-table.d.ts +174 -0
- package/dist/string/method-table.js +805 -0
- package/dist/string/method-table.js.map +1 -0
- package/dist/string/scrub.d.ts +12 -0
- package/dist/string/scrub.js +33 -0
- package/dist/string/scrub.js.map +1 -0
- package/dist/string/slice.d.ts +26 -0
- package/dist/string/slice.js +73 -0
- package/dist/string/slice.js.map +1 -0
- package/dist/string/split.d.ts +11 -0
- package/dist/string/split.js +44 -0
- package/dist/string/split.js.map +1 -0
- package/dist/string/sub.d.ts +114 -0
- package/dist/string/sub.js +371 -0
- package/dist/string/sub.js.map +1 -0
- package/dist/string/succ.d.ts +14 -0
- package/dist/string/succ.js +118 -0
- package/dist/string/succ.js.map +1 -0
- package/dist/string/support.d.ts +142 -0
- package/dist/string/support.js +296 -0
- package/dist/string/support.js.map +1 -0
- package/dist/string/tr.d.ts +46 -0
- package/dist/string/tr.js +156 -0
- package/dist/string/tr.js.map +1 -0
- package/dist/string-io.d.ts +166 -0
- package/dist/string-io.js +248 -0
- package/dist/string-io.js.map +1 -0
- package/dist/string-scanner.d.ts +133 -0
- package/dist/string-scanner.js +248 -0
- package/dist/string-scanner.js.map +1 -0
- package/dist/struct.d.ts +54 -0
- package/dist/struct.js +222 -0
- package/dist/struct.js.map +1 -0
- package/dist/symbol.d.ts +48 -0
- package/dist/symbol.js +107 -0
- package/dist/symbol.js.map +1 -0
- package/dist/tempfile.d.ts +173 -0
- package/dist/tempfile.js +295 -0
- package/dist/tempfile.js.map +1 -0
- package/dist/temporal-tag.d.ts +23 -0
- package/dist/temporal-tag.js +29 -0
- package/dist/temporal-tag.js.map +1 -0
- package/dist/thread-error.d.ts +13 -0
- package/dist/thread-error.js +13 -0
- package/dist/thread-error.js.map +1 -0
- package/dist/thread-pool-executor.d.ts +121 -0
- package/dist/thread-pool-executor.js +254 -0
- package/dist/thread-pool-executor.js.map +1 -0
- package/dist/thread.d.ts +211 -0
- package/dist/thread.js +495 -0
- package/dist/thread.js.map +1 -0
- package/dist/timeout.d.ts +29 -0
- package/dist/timeout.js +41 -0
- package/dist/timeout.js.map +1 -0
- package/dist/tse.d.ts +40 -0
- package/dist/tse.js +66 -0
- package/dist/tse.js.map +1 -0
- package/dist/type-error.d.ts +14 -0
- package/dist/type-error.js +14 -0
- package/dist/type-error.js.map +1 -0
- package/dist/undefined-conversion-error.d.ts +10 -0
- package/dist/undefined-conversion-error.js +10 -0
- package/dist/undefined-conversion-error.js.map +1 -0
- package/dist/uri/common.d.ts +209 -0
- package/dist/uri/common.js +369 -0
- package/dist/uri/common.js.map +1 -0
- package/dist/uri/generic.d.ts +280 -0
- package/dist/uri/generic.js +806 -0
- package/dist/uri/generic.js.map +1 -0
- package/dist/uri/http.d.ts +23 -0
- package/dist/uri/http.js +30 -0
- package/dist/uri/http.js.map +1 -0
- package/dist/uri/https.d.ts +13 -0
- package/dist/uri/https.js +15 -0
- package/dist/uri/https.js.map +1 -0
- package/dist/uri/rfc2396-parser.d.ts +70 -0
- package/dist/uri/rfc2396-parser.js +264 -0
- package/dist/uri/rfc2396-parser.js.map +1 -0
- package/dist/uri/rfc3986-parser.d.ts +46 -0
- package/dist/uri/rfc3986-parser.js +171 -0
- package/dist/uri/rfc3986-parser.js.map +1 -0
- package/dist/uri.d.ts +13 -0
- package/dist/uri.js +13 -0
- package/dist/uri.js.map +1 -0
- package/dist/variable.d.ts +183 -0
- package/dist/variable.js +463 -0
- package/dist/variable.js.map +1 -0
- package/dist/verbose.d.ts +39 -0
- package/dist/verbose.js +49 -0
- package/dist/verbose.js.map +1 -0
- package/dist/yaml.d.ts +9 -0
- package/dist/yaml.js +9 -0
- package/dist/yaml.js.map +1 -0
- package/dist/zlib-adapter.d.ts +119 -0
- package/dist/zlib-adapter.js +230 -0
- package/dist/zlib-adapter.js.map +1 -0
- package/dist/zlib.d.ts +299 -0
- package/dist/zlib.js +679 -0
- package/dist/zlib.js.map +1 -0
- package/package.json +172 -3
|
@@ -0,0 +1,1824 @@
|
|
|
1
|
+
import { ArgumentError } from "./argument-error.js";
|
|
2
|
+
import { classModule } from "./class-module.js";
|
|
3
|
+
import { Dir } from "./dir.js";
|
|
4
|
+
import { File, rbGetPath } from "./file.js";
|
|
5
|
+
import { getFs, getPath } from "./fs-adapter.js";
|
|
6
|
+
import { IO } from "./io.js";
|
|
7
|
+
import { NotImplementedError } from "./not-implemented-error.js";
|
|
8
|
+
import { rbObjRespondTo, rtest } from "./object.js";
|
|
9
|
+
import { syserrTbl } from "./standard-error.js";
|
|
10
|
+
import { stdout } from "./process-adapter.js";
|
|
11
|
+
import { stringSplit } from "./string/split.js";
|
|
12
|
+
/** `File.directory?` (`vendor/ruby/v3.3.11/file.c:1615`). */
|
|
13
|
+
function isDirectory(path) {
|
|
14
|
+
try {
|
|
15
|
+
return getFs().statSync(path).isDirectory();
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* `SystemCallError` (`vendor/ruby/v3.3.11/error.c:3380`), the parent of the `Errno`
|
|
23
|
+
* classes — which is what the fs backend's own errors are: they carry a
|
|
24
|
+
* `.code`. Anything else propagates, as it does past Ruby's
|
|
25
|
+
* `rescue SystemCallError`.
|
|
26
|
+
*/
|
|
27
|
+
function isSystemCallError(error) {
|
|
28
|
+
return syserrTbl.has(String(error?.code));
|
|
29
|
+
}
|
|
30
|
+
/** `Entry_#exist?` / `#directory?` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2109,2123`). */
|
|
31
|
+
function statOrNull(path) {
|
|
32
|
+
try {
|
|
33
|
+
return getFs().statSync(path);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* `Errno::EEXIST` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1163`) — a `SystemCallError`,
|
|
41
|
+
* whose `.code` the fs layer's own errors carry and callers branch on.
|
|
42
|
+
*/
|
|
43
|
+
function errnoEexist(path) {
|
|
44
|
+
const error = new Error(`File exists - ${path}`);
|
|
45
|
+
error.code = "EEXIST";
|
|
46
|
+
return error;
|
|
47
|
+
}
|
|
48
|
+
/** `remove_trailing_slash` (`vendor/ruby/v3.3.11/lib/fileutils.rb:276-278`). */
|
|
49
|
+
function removeTrailingSlash(dir) {
|
|
50
|
+
return dir === "/" ? dir : dir.endsWith("/") ? dir.slice(0, -1) : dir;
|
|
51
|
+
}
|
|
52
|
+
/** `fu_list` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2461-2463`). */
|
|
53
|
+
function fuList(arg) {
|
|
54
|
+
return Array.isArray(arg) ? [...arg] : [arg];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* `fu_mkdir` (`vendor/ruby/v3.3.11/lib/fileutils.rb:396-404`). Ruby's `Dir.mkdir path,
|
|
58
|
+
* mode` takes the mode in the create call; the backend contract's `mkdirSync`
|
|
59
|
+
* does not, so the mode arrives through the `File.chmod` half alone.
|
|
60
|
+
*/
|
|
61
|
+
function fuMkdir(path, mode) {
|
|
62
|
+
path = removeTrailingSlash(path);
|
|
63
|
+
if (mode != null) {
|
|
64
|
+
getFs().mkdirSync(path);
|
|
65
|
+
getFs().chmodSync?.(path, mode);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
getFs().mkdirSync(path);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** `fu_same?` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2491-2493`) — `File.identical?`. */
|
|
72
|
+
function fuSame(a, b) {
|
|
73
|
+
const realpathSync = getFs().realpathSync;
|
|
74
|
+
if (!realpathSync)
|
|
75
|
+
return a === b;
|
|
76
|
+
try {
|
|
77
|
+
return realpathSync(a) === realpathSync(b);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** `fu_each_src_dest0` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2474-2489`). */
|
|
84
|
+
function fuEachSrcDest0(src, dest, yieldFn, targetDirectory = true) {
|
|
85
|
+
if (Array.isArray(src)) {
|
|
86
|
+
for (const s of src) {
|
|
87
|
+
yieldFn(s, targetDirectory ? getPath().join(dest, getPath().basename(s)) : dest);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
if (targetDirectory && isDirectory(dest)) {
|
|
92
|
+
yieldFn(src, getPath().join(dest, getPath().basename(src)));
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
yieldFn(src, dest);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** `fu_each_src_dest` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2466-2472`). */
|
|
100
|
+
function fuEachSrcDest(src, dest, yieldFn) {
|
|
101
|
+
fuEachSrcDest0(src, dest, (s, d) => {
|
|
102
|
+
if (fuSame(s, d))
|
|
103
|
+
throw new ArgumentError(`same file: ${s} and ${d}`);
|
|
104
|
+
yieldFn(s, d);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* `File.lchown` (`vendor/ruby/v3.3.11/file.c:3567`), which raises `NotImplementedError`
|
|
109
|
+
* on a platform whose C library has no `lchown` — spelled here as a backend
|
|
110
|
+
* with no `lchownSync`.
|
|
111
|
+
*/
|
|
112
|
+
function fileLchown(uid, gid, path) {
|
|
113
|
+
const lchownSync = getFs().lchownSync;
|
|
114
|
+
if (!lchownSync)
|
|
115
|
+
throw new NotImplementedError("lchown() function is unimplemented on this machine");
|
|
116
|
+
lchownSync(path, uid, gid);
|
|
117
|
+
}
|
|
118
|
+
/** `File.lchmod` (`vendor/ruby/v3.3.11/file.c:3211`), `NotImplementedError` as above. */
|
|
119
|
+
function fileLchmod(mode, path) {
|
|
120
|
+
const lchmodSync = getFs().lchmodSync;
|
|
121
|
+
if (!lchmodSync)
|
|
122
|
+
throw new NotImplementedError("lchmod() function is unimplemented on this machine");
|
|
123
|
+
lchmodSync(path, mode);
|
|
124
|
+
}
|
|
125
|
+
/** `File.readlink` (`vendor/ruby/v3.3.11/file.c:3081`). */
|
|
126
|
+
function fileReadlink(path) {
|
|
127
|
+
const readlinkSync = getFs().readlinkSync;
|
|
128
|
+
if (!readlinkSync)
|
|
129
|
+
throw new NotImplementedError("readlink() function is unimplemented on this machine");
|
|
130
|
+
return readlinkSync(path);
|
|
131
|
+
}
|
|
132
|
+
/** `File.symlink` (`vendor/ruby/v3.3.11/file.c:3033`). */
|
|
133
|
+
function fileSymlink(old, newName) {
|
|
134
|
+
const symlinkSync = getFs().symlinkSync;
|
|
135
|
+
if (!symlinkSync)
|
|
136
|
+
throw new NotImplementedError("symlink() function is unimplemented on this machine");
|
|
137
|
+
symlinkSync(old, newName);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* `File.utime` (`vendor/ruby/v3.3.11/file.c:2983`). `utimesSync` is optional on the
|
|
141
|
+
* backend contract, and an adapter without one still has to raise `ENOENT` for
|
|
142
|
+
* a missing path — which is the branch `touch` reads — so the fallback stats
|
|
143
|
+
* the path for exactly that, and no-ops the timestamp update itself: against
|
|
144
|
+
* such an adapter `touch` creates a missing file but does not move an existing
|
|
145
|
+
* one's mtime.
|
|
146
|
+
*/
|
|
147
|
+
function fileUtime(atime, mtime, path) {
|
|
148
|
+
const utimesSync = getFs().utimesSync;
|
|
149
|
+
if (utimesSync) {
|
|
150
|
+
utimesSync(path, atime, mtime);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
getFs().statSync(path);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* `Entry_` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2069-2459`), the one directory-tree
|
|
157
|
+
* walker every recursive `FileUtils` body is written against: `copy_entry`
|
|
158
|
+
* (`fileutils.rb:1044-1052`) hands it two procs, `remove_entry`
|
|
159
|
+
* (`fileutils.rb:1450`) traverses it in postorder.
|
|
160
|
+
*
|
|
161
|
+
* `stat` / `stat!` and `platform_support` are only reachable from
|
|
162
|
+
* members no Rails body sends, and `fu_windows?` is false for every backend
|
|
163
|
+
* here, so `platform_support`'s retry has no arm to select either. The
|
|
164
|
+
* `chardev?`-through-`pipe?` predicates read the backend's own `FsStatResult`
|
|
165
|
+
* predicates, which are optional on the contract and answer false when a
|
|
166
|
+
* backend has none.
|
|
167
|
+
*/
|
|
168
|
+
class Entry_ {
|
|
169
|
+
_prefix = null;
|
|
170
|
+
_rel = null;
|
|
171
|
+
_path = null;
|
|
172
|
+
_deref;
|
|
173
|
+
_lstat = null;
|
|
174
|
+
/**
|
|
175
|
+
* `Entry_::S_IF_DOOR` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2153`), the file-type
|
|
176
|
+
* bits `door?` masks a mode against. `private` because `Entry_` itself is
|
|
177
|
+
* Ruby's `internal use only` class and `door?` is its only reader: a public
|
|
178
|
+
* constant in a file no Rails file maps onto is measured extra surface, and
|
|
179
|
+
* a `@noRailsEquivalent` receipt cannot reach it — a literal constant is
|
|
180
|
+
* collected by `extractFileConstants`, which carries no tag.
|
|
181
|
+
*/
|
|
182
|
+
static S_IF_DOOR = 0xd000;
|
|
183
|
+
/** `Entry_#initialize` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2072-2083`). */
|
|
184
|
+
constructor(a, b = null, deref = false) {
|
|
185
|
+
if (b != null) {
|
|
186
|
+
this._prefix = a;
|
|
187
|
+
this._rel = b;
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
this._path = a;
|
|
191
|
+
}
|
|
192
|
+
this._deref = deref;
|
|
193
|
+
}
|
|
194
|
+
/** `Entry_#path` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2089-2095`). */
|
|
195
|
+
get path() {
|
|
196
|
+
if (this._path != null) {
|
|
197
|
+
return this._path;
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
return this.join(this.prefix, this.rel);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/** `Entry_#prefix` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2097-2099`). */
|
|
204
|
+
get prefix() {
|
|
205
|
+
return this._prefix ?? this._path;
|
|
206
|
+
}
|
|
207
|
+
/** `Entry_#rel` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2101-2103`). */
|
|
208
|
+
get rel() {
|
|
209
|
+
return this._rel;
|
|
210
|
+
}
|
|
211
|
+
/** `Entry_#dereference?` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2105-2107`). */
|
|
212
|
+
get isDereference() {
|
|
213
|
+
return this._deref;
|
|
214
|
+
}
|
|
215
|
+
/** `Entry_#file?` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2118-2121`). */
|
|
216
|
+
get isFile() {
|
|
217
|
+
const s = this.lstatBang();
|
|
218
|
+
return s != null && s.isFile();
|
|
219
|
+
}
|
|
220
|
+
/** `Entry_#directory?` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2123-2126`). */
|
|
221
|
+
get isDirectory() {
|
|
222
|
+
const s = this.lstatBang();
|
|
223
|
+
return s != null && s.isDirectory();
|
|
224
|
+
}
|
|
225
|
+
/** `Entry_#symlink?` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2128-2131`). */
|
|
226
|
+
get isSymlink() {
|
|
227
|
+
const s = this.lstatBang();
|
|
228
|
+
return s != null && s.isSymbolicLink?.() === true;
|
|
229
|
+
}
|
|
230
|
+
/** `Entry_#chardev?` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2133-2136`). */
|
|
231
|
+
get isChardev() {
|
|
232
|
+
const s = this.lstatBang();
|
|
233
|
+
return s != null && s.isCharacterDevice?.() === true;
|
|
234
|
+
}
|
|
235
|
+
/** `Entry_#blockdev?` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2138-2141`). */
|
|
236
|
+
get isBlockdev() {
|
|
237
|
+
const s = this.lstatBang();
|
|
238
|
+
return s != null && s.isBlockDevice?.() === true;
|
|
239
|
+
}
|
|
240
|
+
/** `Entry_#socket?` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2143-2146`). */
|
|
241
|
+
get isSocket() {
|
|
242
|
+
const s = this.lstatBang();
|
|
243
|
+
return s != null && s.isSocket?.() === true;
|
|
244
|
+
}
|
|
245
|
+
/** `Entry_#pipe?` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2148-2151`). */
|
|
246
|
+
get isPipe() {
|
|
247
|
+
const s = this.lstatBang();
|
|
248
|
+
return s != null && s.isFIFO?.() === true;
|
|
249
|
+
}
|
|
250
|
+
/** `Entry_#door?` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2155-2158`). */
|
|
251
|
+
get isDoor() {
|
|
252
|
+
const s = this.lstatBang();
|
|
253
|
+
return s != null && (s.mode & 0xf000) === Entry_.S_IF_DOOR;
|
|
254
|
+
}
|
|
255
|
+
/** `Entry_#entries` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2159-2167`). */
|
|
256
|
+
entries() {
|
|
257
|
+
const files = Dir.children(this.path);
|
|
258
|
+
return files.map((n) => new Entry_(this.prefix, this.join(this.rel, n)));
|
|
259
|
+
}
|
|
260
|
+
/** `Entry_#lstat` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2192-2198`). */
|
|
261
|
+
lstat() {
|
|
262
|
+
if (this.isDereference) {
|
|
263
|
+
return (this._lstat ??= getFs().statSync(this.path));
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
return (this._lstat ??= getFs().lstatSync(this.path));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/** `Entry_#lstat!` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2200-2204`). */
|
|
270
|
+
lstatBang() {
|
|
271
|
+
try {
|
|
272
|
+
return this.lstat();
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
if (!isSystemCallError(error))
|
|
276
|
+
throw error;
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* `Entry_#copy` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2239-2274`).
|
|
282
|
+
*
|
|
283
|
+
* The `socket?` and `pipe?` arms each raise before their copy under an
|
|
284
|
+
* interpreter that answers no `UNIXServer` (`fileutils.rb:2258-2263`) and no
|
|
285
|
+
* `File.mkfifo` (`fileutils.rb:2267`); neither constant exists here, so those
|
|
286
|
+
* are the arms taken.
|
|
287
|
+
*/
|
|
288
|
+
copy(dest) {
|
|
289
|
+
this.lstat();
|
|
290
|
+
if (this.isFile) {
|
|
291
|
+
this.copyFile(dest);
|
|
292
|
+
}
|
|
293
|
+
else if (this.isDirectory) {
|
|
294
|
+
if (!File.isExist(dest) && this.isDescendantDirectory(dest, this.path)) {
|
|
295
|
+
throw new ArgumentError(`cannot copy directory ${this.path} to itself ${dest}`);
|
|
296
|
+
}
|
|
297
|
+
try {
|
|
298
|
+
Dir.mkdir(dest);
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
if (!File.isDirectory(dest))
|
|
302
|
+
throw error;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
else if (this.isSymlink) {
|
|
306
|
+
fileSymlink(fileReadlink(this.path), dest);
|
|
307
|
+
}
|
|
308
|
+
else if (this.isChardev || this.isBlockdev) {
|
|
309
|
+
throw new Error("cannot handle device file");
|
|
310
|
+
}
|
|
311
|
+
else if (this.isSocket) {
|
|
312
|
+
throw new Error("cannot handle socket");
|
|
313
|
+
}
|
|
314
|
+
else if (this.isPipe) {
|
|
315
|
+
throw new Error("cannot handle FIFO");
|
|
316
|
+
}
|
|
317
|
+
else if (this.isDoor) {
|
|
318
|
+
throw new Error(`cannot handle door: ${this.path}`);
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
throw new Error(`unknown file type: ${this.path}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/** `Entry_#copy_file` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2277-2283`). */
|
|
325
|
+
copyFile(dest) {
|
|
326
|
+
File.open(this.path, "r", (s) => {
|
|
327
|
+
File.open(dest, "wb", { perm: s.stat().mode }, (f) => {
|
|
328
|
+
IO.copyStream(s, f);
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
/** `Entry_#copy_metadata` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2285-2312`). */
|
|
333
|
+
copyMetadata(path) {
|
|
334
|
+
const st = this.lstat();
|
|
335
|
+
const symlink = st.isSymbolicLink?.() === true;
|
|
336
|
+
if (!symlink) {
|
|
337
|
+
fileUtime(st.atime, st.mtime, path);
|
|
338
|
+
}
|
|
339
|
+
let mode = st.mode;
|
|
340
|
+
try {
|
|
341
|
+
if (symlink) {
|
|
342
|
+
try {
|
|
343
|
+
fileLchown(st.uid, st.gid, path);
|
|
344
|
+
}
|
|
345
|
+
catch (error) {
|
|
346
|
+
if (!(error instanceof NotImplementedError))
|
|
347
|
+
throw error;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
getFs().chownSync?.(path, st.uid, st.gid);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
const code = error.code;
|
|
356
|
+
if (code !== "EPERM" && code !== "EACCES")
|
|
357
|
+
throw error;
|
|
358
|
+
mode &= 0o1777;
|
|
359
|
+
}
|
|
360
|
+
if (symlink) {
|
|
361
|
+
try {
|
|
362
|
+
fileLchmod(mode, path);
|
|
363
|
+
}
|
|
364
|
+
catch (error) {
|
|
365
|
+
const code = error.code;
|
|
366
|
+
if (!(error instanceof NotImplementedError) && code !== "EOPNOTSUPP")
|
|
367
|
+
throw error;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
getFs().chmodSync?.(path, mode);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/** `Entry_#remove` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2314-2320`). */
|
|
375
|
+
remove() {
|
|
376
|
+
if (this.isDirectory) {
|
|
377
|
+
this.removeDir1();
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
this.removeFile();
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
/** `Entry_#remove_dir1` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2322-2326`). */
|
|
384
|
+
removeDir1() {
|
|
385
|
+
getFs().rmdirSync(removeTrailingSlash(this.path));
|
|
386
|
+
}
|
|
387
|
+
/** `Entry_#remove_file` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2328-2332`). */
|
|
388
|
+
removeFile() {
|
|
389
|
+
getFs().unlinkSync(this.path);
|
|
390
|
+
}
|
|
391
|
+
/** `Entry_#preorder_traverse` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2354-2360`). */
|
|
392
|
+
preorderTraverse(yieldFn) {
|
|
393
|
+
const stack = [this];
|
|
394
|
+
let ent;
|
|
395
|
+
while ((ent = stack.pop()) != null) {
|
|
396
|
+
yieldFn(ent);
|
|
397
|
+
if (ent.isDirectory)
|
|
398
|
+
stack.push(...ent.entries().reverse());
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
/** `Entry_#postorder_traverse` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2364-2382`). */
|
|
402
|
+
postorderTraverse(yieldFn) {
|
|
403
|
+
if (this.isDirectory) {
|
|
404
|
+
let children;
|
|
405
|
+
try {
|
|
406
|
+
children = this.entries();
|
|
407
|
+
}
|
|
408
|
+
catch (error) {
|
|
409
|
+
if (error.code !== "EACCES")
|
|
410
|
+
throw error;
|
|
411
|
+
yieldFn(this);
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
for (const ent of children) {
|
|
415
|
+
ent.postorderTraverse((e) => {
|
|
416
|
+
yieldFn(e);
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
yieldFn(this);
|
|
421
|
+
}
|
|
422
|
+
async isDirectoryAsync() {
|
|
423
|
+
const s = await this.lstatBangAsync();
|
|
424
|
+
return s != null && s.isDirectory();
|
|
425
|
+
}
|
|
426
|
+
async isSymlinkAsync() {
|
|
427
|
+
const s = await this.lstatBangAsync();
|
|
428
|
+
return s != null && s.isSymbolicLink?.() === true;
|
|
429
|
+
}
|
|
430
|
+
async isFileAsync() {
|
|
431
|
+
const s = await this.lstatBangAsync();
|
|
432
|
+
return s != null && s.isFile();
|
|
433
|
+
}
|
|
434
|
+
async entriesAsync() {
|
|
435
|
+
const files = await Dir.childrenAsync(this.path);
|
|
436
|
+
return files.map((n) => new Entry_(this.prefix, this.join(this.rel, n)));
|
|
437
|
+
}
|
|
438
|
+
async lstatAsync() {
|
|
439
|
+
const fs = getFs();
|
|
440
|
+
if (this.isDereference) {
|
|
441
|
+
return (this._lstat ??= fs.stat ? await fs.stat(this.path) : fs.statSync(this.path));
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
return (this._lstat ??= fs.lstat ? await fs.lstat(this.path) : fs.lstatSync(this.path));
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
async lstatBangAsync() {
|
|
448
|
+
try {
|
|
449
|
+
return await this.lstatAsync();
|
|
450
|
+
}
|
|
451
|
+
catch (error) {
|
|
452
|
+
if (!isSystemCallError(error))
|
|
453
|
+
throw error;
|
|
454
|
+
return null;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
async chmodAsync(mode) {
|
|
458
|
+
try {
|
|
459
|
+
if (await this.isSymlinkAsync()) {
|
|
460
|
+
if (getFs().lchmodSync != null)
|
|
461
|
+
fileLchmod(mode, this.path);
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
await File.chmodAsync(mode, this.path);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
catch (error) {
|
|
468
|
+
if (error.code !== "EOPNOTSUPP")
|
|
469
|
+
throw error;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
/** `Entry_#chown` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2215-2221`). */
|
|
473
|
+
async chownAsync(uid, gid) {
|
|
474
|
+
if (await this.isSymlinkAsync()) {
|
|
475
|
+
if (getFs().lchown != null)
|
|
476
|
+
await getFs().lchown(this.path, uid ?? -1, gid ?? -1);
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
await File.chownAsync(uid, gid, this.path);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
/** `Entry_#link` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2223-2237`). */
|
|
483
|
+
async linkAsync(dest) {
|
|
484
|
+
if (await this.isDirectoryAsync()) {
|
|
485
|
+
if (!(await File.isExistAsync(dest)) && this.isDescendantDirectory(dest, this.path)) {
|
|
486
|
+
throw new ArgumentError(`cannot link directory ${this.path} to itself ${dest}`);
|
|
487
|
+
}
|
|
488
|
+
try {
|
|
489
|
+
await getFs().mkdir(dest);
|
|
490
|
+
}
|
|
491
|
+
catch (error) {
|
|
492
|
+
if (!(await File.isDirectoryAsync(dest)))
|
|
493
|
+
throw error;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
await File.linkAsync(this.path, dest);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
async copyAsync(dest) {
|
|
501
|
+
await this.lstatAsync();
|
|
502
|
+
if (this.isFile) {
|
|
503
|
+
await this.copyFileAsync(dest);
|
|
504
|
+
}
|
|
505
|
+
else if (this.isDirectory) {
|
|
506
|
+
if (!(await File.isExistAsync(dest)) && this.isDescendantDirectory(dest, this.path)) {
|
|
507
|
+
throw new ArgumentError(`cannot copy directory ${this.path} to itself ${dest}`);
|
|
508
|
+
}
|
|
509
|
+
try {
|
|
510
|
+
await getFs().mkdir(dest);
|
|
511
|
+
}
|
|
512
|
+
catch (error) {
|
|
513
|
+
if (!(await File.isDirectoryAsync(dest)))
|
|
514
|
+
throw error;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
else if (this.isSymlink) {
|
|
518
|
+
await File.symlinkAsync(await getFs().readlink(this.path), dest);
|
|
519
|
+
}
|
|
520
|
+
else if (this.isChardev || this.isBlockdev) {
|
|
521
|
+
throw new Error("cannot handle device file");
|
|
522
|
+
}
|
|
523
|
+
else if (this.isSocket) {
|
|
524
|
+
throw new Error("cannot handle socket");
|
|
525
|
+
}
|
|
526
|
+
else if (this.isPipe) {
|
|
527
|
+
throw new Error("cannot handle FIFO");
|
|
528
|
+
}
|
|
529
|
+
else if (this.isDoor) {
|
|
530
|
+
throw new Error(`cannot handle door: ${this.path}`);
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
throw new Error(`unknown file type: ${this.path}`);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
async copyFileAsync(dest) {
|
|
537
|
+
const fs = getFs();
|
|
538
|
+
await fs.writeFile(dest, await fs.readFile(this.path), {
|
|
539
|
+
mode: (await fs.stat(this.path)).mode,
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
async copyMetadataAsync(path) {
|
|
543
|
+
const st = await this.lstatAsync();
|
|
544
|
+
const symlink = st.isSymbolicLink?.() === true;
|
|
545
|
+
if (!symlink) {
|
|
546
|
+
await File.utimeAsync(st.atime, st.mtime, path);
|
|
547
|
+
}
|
|
548
|
+
let mode = st.mode;
|
|
549
|
+
try {
|
|
550
|
+
if (symlink) {
|
|
551
|
+
try {
|
|
552
|
+
if (getFs().lchown)
|
|
553
|
+
await getFs().lchown(path, st.uid, st.gid);
|
|
554
|
+
else
|
|
555
|
+
fileLchown(st.uid, st.gid, path);
|
|
556
|
+
}
|
|
557
|
+
catch (error) {
|
|
558
|
+
if (!(error instanceof NotImplementedError))
|
|
559
|
+
throw error;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
await File.chownAsync(st.uid, st.gid, path);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
catch (error) {
|
|
567
|
+
const code = error.code;
|
|
568
|
+
if (code !== "EPERM" && code !== "EACCES")
|
|
569
|
+
throw error;
|
|
570
|
+
mode &= 0o1777;
|
|
571
|
+
}
|
|
572
|
+
if (symlink) {
|
|
573
|
+
try {
|
|
574
|
+
fileLchmod(mode, path);
|
|
575
|
+
}
|
|
576
|
+
catch (error) {
|
|
577
|
+
const code = error.code;
|
|
578
|
+
if (!(error instanceof NotImplementedError) && code !== "EOPNOTSUPP")
|
|
579
|
+
throw error;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
await File.chmodAsync(mode, path);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
async removeAsync() {
|
|
587
|
+
if (await this.isDirectoryAsync()) {
|
|
588
|
+
await this.removeDir1Async();
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
await this.removeFileAsync();
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
async removeDir1Async() {
|
|
595
|
+
const fs = getFs();
|
|
596
|
+
const path = removeTrailingSlash(this.path);
|
|
597
|
+
if (fs.rmdir)
|
|
598
|
+
await fs.rmdir(path);
|
|
599
|
+
else
|
|
600
|
+
fs.rmdirSync(path);
|
|
601
|
+
}
|
|
602
|
+
async removeFileAsync() {
|
|
603
|
+
const fs = getFs();
|
|
604
|
+
if (fs.unlink)
|
|
605
|
+
await fs.unlink(this.path);
|
|
606
|
+
else
|
|
607
|
+
fs.unlinkSync(this.path);
|
|
608
|
+
}
|
|
609
|
+
async preorderTraverseAsync(yieldFn) {
|
|
610
|
+
const stack = [this];
|
|
611
|
+
let ent;
|
|
612
|
+
while ((ent = stack.pop()) != null) {
|
|
613
|
+
await yieldFn(ent);
|
|
614
|
+
if (await ent.isDirectoryAsync())
|
|
615
|
+
stack.push(...(await ent.entriesAsync()).reverse());
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
async postorderTraverseAsync(yieldFn) {
|
|
619
|
+
if (await this.isDirectoryAsync()) {
|
|
620
|
+
let children;
|
|
621
|
+
try {
|
|
622
|
+
children = await this.entriesAsync();
|
|
623
|
+
}
|
|
624
|
+
catch (error) {
|
|
625
|
+
if (error.code !== "EACCES")
|
|
626
|
+
throw error;
|
|
627
|
+
await yieldFn(this);
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
for (const ent of children) {
|
|
631
|
+
await ent.postorderTraverseAsync(async (e) => {
|
|
632
|
+
await yieldFn(e);
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
await yieldFn(this);
|
|
637
|
+
}
|
|
638
|
+
async wrapTraverseAsync(pre, post) {
|
|
639
|
+
await pre(this);
|
|
640
|
+
if (await this.isDirectoryAsync()) {
|
|
641
|
+
for (const ent of await this.entriesAsync()) {
|
|
642
|
+
await ent.wrapTraverseAsync(pre, post);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
await post(this);
|
|
646
|
+
}
|
|
647
|
+
/** `Entry_#wrap_traverse` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2386-2393`). */
|
|
648
|
+
wrapTraverse(pre, post) {
|
|
649
|
+
pre(this);
|
|
650
|
+
if (this.isDirectory) {
|
|
651
|
+
for (const ent of this.entries()) {
|
|
652
|
+
ent.wrapTraverse(pre, post);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
post(this);
|
|
656
|
+
}
|
|
657
|
+
/** `Entry_#join` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2432-2446`). */
|
|
658
|
+
join(dir, base) {
|
|
659
|
+
if (base == null || base === ".")
|
|
660
|
+
return dir;
|
|
661
|
+
if (dir == null || dir === ".")
|
|
662
|
+
return base;
|
|
663
|
+
return File.join(dir, base);
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* `Entry_#descendant_directory?` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2452-2458`),
|
|
667
|
+
* the guard `Entry_#copy`'s directory arm raises on (`fileutils.rb:2245-2247`).
|
|
668
|
+
*/
|
|
669
|
+
isDescendantDirectory(descendant, ascendant) {
|
|
670
|
+
if (File.FNM_SYSCASE !== 0) {
|
|
671
|
+
return (File.expandPath(File.dirname(descendant)).toLowerCase() ===
|
|
672
|
+
File.expandPath(ascendant).toLowerCase());
|
|
673
|
+
}
|
|
674
|
+
else {
|
|
675
|
+
return File.expandPath(File.dirname(descendant)) === File.expandPath(ascendant);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
/** `$stdout` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2498`), reached through the process
|
|
680
|
+
* backend so the leaf writes without importing one. */
|
|
681
|
+
const fuStdout = {
|
|
682
|
+
puts: (msg) => {
|
|
683
|
+
stdout.write(`${msg}\n`);
|
|
684
|
+
},
|
|
685
|
+
};
|
|
686
|
+
/** `fu_output_message` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2496-2503`). */
|
|
687
|
+
function fuOutputMessage(msg) {
|
|
688
|
+
const output = FileUtils.fileutilsOutput ?? fuStdout;
|
|
689
|
+
if (FileUtils.fileutilsLabel != null) {
|
|
690
|
+
msg = FileUtils.fileutilsLabel + msg;
|
|
691
|
+
}
|
|
692
|
+
output.puts(msg);
|
|
693
|
+
}
|
|
694
|
+
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
|
|
695
|
+
/**
|
|
696
|
+
* Ruby's `FileUtils` (stdlib, `vendor/ruby/v3.3.11/lib/fileutils.rb:1`), the file
|
|
697
|
+
* operations Rails sends from ported bodies — `mkdir_p` when a schema dump or a
|
|
698
|
+
* cache root has to exist, `rm`/`rm_f`/`rm_r` when one is torn down, `cp`, `mv`
|
|
699
|
+
* and `touch`. Only the members Ruby code in this repo sends are ported.
|
|
700
|
+
*
|
|
701
|
+
* Every member runs against the filesystem backend `fs-adapter.ts` resolves, so
|
|
702
|
+
* `FileUtils` is synchronous exactly as Ruby's is, and a caller reads the same
|
|
703
|
+
* `FileUtils.mkdir_p(dir)` a Rails dev reads.
|
|
704
|
+
*
|
|
705
|
+
* Each method is `module_function` (`vendor/ruby/v3.3.11/lib/fileutils.rb:185-188`),
|
|
706
|
+
* so it is both a static and a prototype member, and `include FileUtils` answers `cd`.
|
|
707
|
+
*
|
|
708
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib, not Rails: `FileUtils` ships with
|
|
709
|
+
* the interpreter, so no Rails file defines it and no port can remove the need
|
|
710
|
+
* for it while Rails bodies send `FileUtils.mkdir_p` and friends.
|
|
711
|
+
*/
|
|
712
|
+
export class FileUtils {
|
|
713
|
+
/** @noRailsEquivalent PERMANENT */
|
|
714
|
+
static [classModule] = true;
|
|
715
|
+
/** `@fileutils_output` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2497`), the sink
|
|
716
|
+
* `fu_output_message` writes to when a host has set one.
|
|
717
|
+
* @noRailsEquivalent PERMANENT — the JS spelling of a Ruby module instance
|
|
718
|
+
* variable, which has no member of its own to mirror.
|
|
719
|
+
*/
|
|
720
|
+
static fileutilsOutput;
|
|
721
|
+
/** `@fileutils_label` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2500`), prefixed to
|
|
722
|
+
* every message when a host has set one.
|
|
723
|
+
* @noRailsEquivalent PERMANENT — the JS spelling of a Ruby module instance
|
|
724
|
+
* variable, which has no member of its own to mirror.
|
|
725
|
+
*/
|
|
726
|
+
static fileutilsLabel;
|
|
727
|
+
/** `fu_split_path` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2506-2515`).
|
|
728
|
+
* @noRailsEquivalent PERMANENT
|
|
729
|
+
*/
|
|
730
|
+
static fuSplitPath(path) {
|
|
731
|
+
const list = [];
|
|
732
|
+
for (;;) {
|
|
733
|
+
const [parent, base] = File.split(path);
|
|
734
|
+
if (parent === path || parent === ".")
|
|
735
|
+
break;
|
|
736
|
+
list.push(base);
|
|
737
|
+
path = parent;
|
|
738
|
+
}
|
|
739
|
+
list.push(path);
|
|
740
|
+
return list.reverse();
|
|
741
|
+
}
|
|
742
|
+
/** `fu_relative_components_from` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2518-2524`).
|
|
743
|
+
* @noRailsEquivalent PERMANENT
|
|
744
|
+
*/
|
|
745
|
+
static fuRelativeComponentsFrom(target, base) {
|
|
746
|
+
let i = 0;
|
|
747
|
+
while (target[i] != null && target[i] === base[i]) {
|
|
748
|
+
i += 1;
|
|
749
|
+
}
|
|
750
|
+
return new Array(base.length - i).fill("..").concat(target.slice(i));
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* `fu_clean_components` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2527-2542`). MRI's
|
|
754
|
+
* `path.chomp!(regexp, "")` at `:2535` is an `ArgumentError`, since `chomp!`
|
|
755
|
+
* takes one argument; this is the `sub!` that line means.
|
|
756
|
+
*
|
|
757
|
+
* @missingRailsCall chomp! — PERMANENT
|
|
758
|
+
* @noRailsEquivalent PERMANENT
|
|
759
|
+
*/
|
|
760
|
+
static async fuCleanComponentsAsync(...comp) {
|
|
761
|
+
while (comp[0] === ".")
|
|
762
|
+
comp.shift();
|
|
763
|
+
if (comp.length === 0)
|
|
764
|
+
return comp;
|
|
765
|
+
const clean = [comp.shift()];
|
|
766
|
+
let path = File.join(...clean, "");
|
|
767
|
+
while (comp.length > 0) {
|
|
768
|
+
const c = comp.shift();
|
|
769
|
+
if (c === ".." &&
|
|
770
|
+
clean.at(-1) !== ".." &&
|
|
771
|
+
!(getFs().symlink != null && (await File.isSymlinkAsync(path)))) {
|
|
772
|
+
clean.pop();
|
|
773
|
+
path = path.replace(/(?<=^|\/)[^/]+\/$/, "");
|
|
774
|
+
}
|
|
775
|
+
else {
|
|
776
|
+
clean.push(c);
|
|
777
|
+
path += `${c}/`;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return clean;
|
|
781
|
+
}
|
|
782
|
+
/** `fu_starting_path?` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2550-2552`).
|
|
783
|
+
* @noRailsEquivalent PERMANENT
|
|
784
|
+
*/
|
|
785
|
+
static isFuStartingPath(path) {
|
|
786
|
+
return path != null && path.startsWith("/");
|
|
787
|
+
}
|
|
788
|
+
/** `user_mask` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1642-1657`).
|
|
789
|
+
* @noRailsEquivalent PERMANENT
|
|
790
|
+
*/
|
|
791
|
+
static userMask(target) {
|
|
792
|
+
return [...target].reduce((mask, chr) => {
|
|
793
|
+
switch (chr) {
|
|
794
|
+
case "u":
|
|
795
|
+
return mask | 0o4700;
|
|
796
|
+
case "g":
|
|
797
|
+
return mask | 0o2070;
|
|
798
|
+
case "o":
|
|
799
|
+
return mask | 0o1007;
|
|
800
|
+
case "a":
|
|
801
|
+
return mask | 0o7777;
|
|
802
|
+
default:
|
|
803
|
+
throw new ArgumentError(`invalid \`who' symbol in file mode: ${chr}`);
|
|
804
|
+
}
|
|
805
|
+
}, 0);
|
|
806
|
+
}
|
|
807
|
+
/** `apply_mask` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1660-1669`).
|
|
808
|
+
* @noRailsEquivalent PERMANENT
|
|
809
|
+
*/
|
|
810
|
+
static applyMask(mode, userMask, op, modeMask) {
|
|
811
|
+
switch (op) {
|
|
812
|
+
case "=":
|
|
813
|
+
return (mode & ~userMask) | (userMask & modeMask);
|
|
814
|
+
case "+":
|
|
815
|
+
return mode | (userMask & modeMask);
|
|
816
|
+
default:
|
|
817
|
+
return mode & ~(userMask & modeMask);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
/** `symbolic_modes_to_i` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1672-1718`).
|
|
821
|
+
* @noRailsEquivalent PERMANENT
|
|
822
|
+
*/
|
|
823
|
+
static async symbolicModesToIAsync(modeSym, path) {
|
|
824
|
+
const st = typeof path === "string" ? await getFs().stat(path) : path;
|
|
825
|
+
let currentMode = st.mode & 0o7777;
|
|
826
|
+
for (const clause of stringSplit(modeSym, ",")) {
|
|
827
|
+
const [target, ...actions] = clause.split(/([=+-])/);
|
|
828
|
+
if (actions.length === 0)
|
|
829
|
+
throw new ArgumentError(`invalid file mode: ${modeSym}`);
|
|
830
|
+
const mask = FileUtils.userMask(target === "" ? "a" : target);
|
|
831
|
+
for (let i = 0; i < actions.length; i += 2) {
|
|
832
|
+
const op = actions[i];
|
|
833
|
+
const perm = actions[i + 1] ?? "";
|
|
834
|
+
let needApply = op === "=";
|
|
835
|
+
let modeMask = 0;
|
|
836
|
+
for (const chr of perm) {
|
|
837
|
+
switch (chr) {
|
|
838
|
+
case "r":
|
|
839
|
+
modeMask |= 0o444;
|
|
840
|
+
break;
|
|
841
|
+
case "w":
|
|
842
|
+
modeMask |= 0o222;
|
|
843
|
+
break;
|
|
844
|
+
case "x":
|
|
845
|
+
modeMask |= 0o111;
|
|
846
|
+
break;
|
|
847
|
+
case "X":
|
|
848
|
+
if (st.isDirectory())
|
|
849
|
+
modeMask |= 0o111;
|
|
850
|
+
break;
|
|
851
|
+
case "s":
|
|
852
|
+
modeMask |= 0o6000;
|
|
853
|
+
break;
|
|
854
|
+
case "t":
|
|
855
|
+
modeMask |= 0o1000;
|
|
856
|
+
break;
|
|
857
|
+
case "u":
|
|
858
|
+
case "g":
|
|
859
|
+
case "o": {
|
|
860
|
+
if (modeMask !== 0)
|
|
861
|
+
currentMode = FileUtils.applyMask(currentMode, mask, op, modeMask);
|
|
862
|
+
needApply = false;
|
|
863
|
+
const copyMask = FileUtils.userMask(chr);
|
|
864
|
+
modeMask = Math.floor((currentMode & copyMask) / (copyMask & 0o111)) * (mask & 0o111);
|
|
865
|
+
break;
|
|
866
|
+
}
|
|
867
|
+
default:
|
|
868
|
+
throw new ArgumentError(`invalid \`perm' symbol in file mode: ${chr}`);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
if (modeMask !== 0 || needApply) {
|
|
872
|
+
currentMode = FileUtils.applyMask(currentMode, mask, op, modeMask);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
return currentMode;
|
|
877
|
+
}
|
|
878
|
+
/** `fu_mode` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1721-1723`).
|
|
879
|
+
* @noRailsEquivalent PERMANENT
|
|
880
|
+
*/
|
|
881
|
+
static async fuModeAsync(mode, path) {
|
|
882
|
+
return typeof mode === "string" ? FileUtils.symbolicModesToIAsync(mode, path) : mode;
|
|
883
|
+
}
|
|
884
|
+
/** `mode_to_s` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1726-1728`).
|
|
885
|
+
* @noRailsEquivalent PERMANENT
|
|
886
|
+
*/
|
|
887
|
+
static modeToS(mode) {
|
|
888
|
+
return typeof mode === "string" ? mode : mode.toString(8);
|
|
889
|
+
}
|
|
890
|
+
/** @noRailsEquivalent PERMANENT */
|
|
891
|
+
static async etcIdAsync(file, name, label) {
|
|
892
|
+
const rows = await getFs().readFile(file, "utf-8");
|
|
893
|
+
for (const row of rows.split("\n")) {
|
|
894
|
+
const fields = row.split(":");
|
|
895
|
+
if (fields[0] === name && /^\d+$/.test(fields[2] ?? ""))
|
|
896
|
+
return Number(fields[2]);
|
|
897
|
+
}
|
|
898
|
+
throw new ArgumentError(`can't find ${label} for ${name}`);
|
|
899
|
+
}
|
|
900
|
+
/** `fu_get_uid` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1933-1944`).
|
|
901
|
+
* @noRailsEquivalent PERMANENT
|
|
902
|
+
*/
|
|
903
|
+
static async fuGetUidAsync(user) {
|
|
904
|
+
if (user == null)
|
|
905
|
+
return null;
|
|
906
|
+
if (typeof user === "number")
|
|
907
|
+
return user;
|
|
908
|
+
if (/^\d+$/.test(user))
|
|
909
|
+
return Number(user);
|
|
910
|
+
return FileUtils.etcIdAsync("/etc/passwd", user, "user");
|
|
911
|
+
}
|
|
912
|
+
/** `fu_get_gid` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1947-1958`).
|
|
913
|
+
* @noRailsEquivalent PERMANENT
|
|
914
|
+
*/
|
|
915
|
+
static async fuGetGidAsync(group) {
|
|
916
|
+
if (group == null)
|
|
917
|
+
return null;
|
|
918
|
+
if (typeof group === "number")
|
|
919
|
+
return group;
|
|
920
|
+
if (/^\d+$/.test(group))
|
|
921
|
+
return Number(group);
|
|
922
|
+
return FileUtils.etcIdAsync("/etc/group", group, "group");
|
|
923
|
+
}
|
|
924
|
+
static cd(dir, options = {}, block) {
|
|
925
|
+
if (typeof options === "function")
|
|
926
|
+
[options, block] = [{}, options];
|
|
927
|
+
const { verbose } = options;
|
|
928
|
+
if (verbose != null && verbose !== false)
|
|
929
|
+
fuOutputMessage(`cd ${dir}`);
|
|
930
|
+
const result = block != null ? Dir.chdir(dir, block) : Dir.chdir(dir);
|
|
931
|
+
if (verbose != null && verbose !== false && block != null) {
|
|
932
|
+
if (result != null && typeof result.then === "function") {
|
|
933
|
+
return Promise.resolve(result).then((value) => {
|
|
934
|
+
fuOutputMessage("cd -");
|
|
935
|
+
return value;
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
fuOutputMessage("cd -");
|
|
939
|
+
}
|
|
940
|
+
return result;
|
|
941
|
+
}
|
|
942
|
+
/** `FileUtils.chdir` (`vendor/ruby/v3.3.11/lib/fileutils.rb:246`), an alias of `cd`.
|
|
943
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
944
|
+
*/
|
|
945
|
+
static chdir = FileUtils.cd;
|
|
946
|
+
/** `FileUtils.mkdir_p` (`vendor/ruby/v3.3.11/lib/fileutils.rb:365-388`).
|
|
947
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
948
|
+
*/
|
|
949
|
+
static mkdirP(list, { mode, noop, verbose } = {}) {
|
|
950
|
+
list = fuList(list);
|
|
951
|
+
if (verbose === true)
|
|
952
|
+
fuOutputMessage(`mkdir -p ${mode != null ? `-m ${mode.toString(8).padStart(3, "0")} ` : ""}${list.join(" ")}`);
|
|
953
|
+
if (noop === true)
|
|
954
|
+
return list;
|
|
955
|
+
for (const item of list) {
|
|
956
|
+
let path = removeTrailingSlash(item);
|
|
957
|
+
const stack = [];
|
|
958
|
+
while (!isDirectory(path) && getPath().dirname(path) !== path) {
|
|
959
|
+
stack.push(path);
|
|
960
|
+
path = getPath().dirname(path);
|
|
961
|
+
}
|
|
962
|
+
for (const dir of stack.reverse()) {
|
|
963
|
+
try {
|
|
964
|
+
fuMkdir(dir, mode);
|
|
965
|
+
}
|
|
966
|
+
catch (error) {
|
|
967
|
+
if (!isSystemCallError(error) || !isDirectory(dir))
|
|
968
|
+
throw error;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
return list;
|
|
973
|
+
}
|
|
974
|
+
/** {@link FileUtils.mkdirP} over the backend's async verbs
|
|
975
|
+
* (`vendor/ruby/v3.3.11/lib/fileutils.rb:365-388`).
|
|
976
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
977
|
+
*/
|
|
978
|
+
static async mkdirPAsync(list, { mode, noop, verbose } = {}) {
|
|
979
|
+
list = fuList(list);
|
|
980
|
+
if (rtest(verbose))
|
|
981
|
+
fuOutputMessage(`mkdir -p ${mode != null ? `-m ${mode.toString(8).padStart(3, "0")} ` : ""}${list.join(" ")}`);
|
|
982
|
+
if (rtest(noop))
|
|
983
|
+
return list;
|
|
984
|
+
const isDirectoryAsync = (path) => getFs().stat(path).then((stat) => stat.isDirectory(), () => false);
|
|
985
|
+
for (const item of list) {
|
|
986
|
+
let path = removeTrailingSlash(item);
|
|
987
|
+
const stack = [];
|
|
988
|
+
while (!(await isDirectoryAsync(path)) && getPath().dirname(path) !== path) {
|
|
989
|
+
stack.push(path);
|
|
990
|
+
path = getPath().dirname(path);
|
|
991
|
+
}
|
|
992
|
+
for (const dir of stack.reverse()) {
|
|
993
|
+
try {
|
|
994
|
+
await FileUtils.fuMkdirAsync(dir, mode);
|
|
995
|
+
}
|
|
996
|
+
catch (error) {
|
|
997
|
+
if (!isSystemCallError(error) || !(await isDirectoryAsync(dir)))
|
|
998
|
+
throw error;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
return list;
|
|
1003
|
+
}
|
|
1004
|
+
/** `FileUtils.mkdir` (`vendor/ruby/v3.3.11/lib/fileutils.rb:316-324`), over async `mkdir`.
|
|
1005
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1006
|
+
*/
|
|
1007
|
+
static async mkdirAsync(list, { mode, noop, verbose } = {}) {
|
|
1008
|
+
list = fuList(list);
|
|
1009
|
+
if (rtest(verbose))
|
|
1010
|
+
fuOutputMessage(`mkdir ${mode != null ? `-m ${mode.toString(8).padStart(3, "0")} ` : ""}${list.join(" ")}`);
|
|
1011
|
+
if (rtest(noop))
|
|
1012
|
+
return;
|
|
1013
|
+
for (const dir of list) {
|
|
1014
|
+
await FileUtils.fuMkdirAsync(dir, mode);
|
|
1015
|
+
}
|
|
1016
|
+
return list;
|
|
1017
|
+
}
|
|
1018
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1019
|
+
static mkpathAsync = FileUtils.mkdirPAsync;
|
|
1020
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1021
|
+
static makedirsAsync = FileUtils.mkdirPAsync;
|
|
1022
|
+
/** `FileUtils.rmdir` (`vendor/ruby/v3.3.11/lib/fileutils.rb:442-458`), over async `rmdir`.
|
|
1023
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1024
|
+
*/
|
|
1025
|
+
static async rmdirAsync(list, { parents, noop, verbose } = {}) {
|
|
1026
|
+
list = fuList(list);
|
|
1027
|
+
if (rtest(verbose))
|
|
1028
|
+
fuOutputMessage(`rmdir ${parents ? "-p " : ""}${list.join(" ")}`);
|
|
1029
|
+
if (rtest(noop))
|
|
1030
|
+
return;
|
|
1031
|
+
for (let dir of list) {
|
|
1032
|
+
await getFs().rmdir((dir = removeTrailingSlash(dir)));
|
|
1033
|
+
if (parents) {
|
|
1034
|
+
try {
|
|
1035
|
+
let parent;
|
|
1036
|
+
while ((parent = File.dirname(dir)) !== "." && parent !== dir) {
|
|
1037
|
+
dir = parent;
|
|
1038
|
+
await getFs().rmdir(dir);
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
catch (error) {
|
|
1042
|
+
const code = error.code;
|
|
1043
|
+
if (code !== "ENOTEMPTY" && code !== "EEXIST" && code !== "ENOENT")
|
|
1044
|
+
throw error;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
return list;
|
|
1049
|
+
}
|
|
1050
|
+
/** `FileUtils.makedirs` (`vendor/ruby/v3.3.11/lib/fileutils.rb:392-394`), an alias of `mkdir_p`.
|
|
1051
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1052
|
+
*/
|
|
1053
|
+
static makedirs = FileUtils.mkdirP;
|
|
1054
|
+
/** `FileUtils.cp` (`vendor/ruby/v3.3.11/lib/fileutils.rb:873-879`).
|
|
1055
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1056
|
+
*/
|
|
1057
|
+
static cp(src, dest, { preserve, noop, verbose } = {}) {
|
|
1058
|
+
if (verbose === true)
|
|
1059
|
+
fuOutputMessage(`cp${preserve === true ? " -p" : ""} ${[src, dest].flat().join(" ")}`);
|
|
1060
|
+
if (noop === true)
|
|
1061
|
+
return;
|
|
1062
|
+
fuEachSrcDest(src, dest, (s, d) => {
|
|
1063
|
+
FileUtils.copyFile(s, d, preserve);
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
/**
|
|
1067
|
+
* @internal
|
|
1068
|
+
* @noRailsEquivalent PERMANENT
|
|
1069
|
+
*/
|
|
1070
|
+
static async fuMkdirAsync(path, mode) {
|
|
1071
|
+
path = removeTrailingSlash(path);
|
|
1072
|
+
if (mode != null) {
|
|
1073
|
+
await getFs().mkdir(path, { mode });
|
|
1074
|
+
await File.chmodAsync(mode, path);
|
|
1075
|
+
}
|
|
1076
|
+
else {
|
|
1077
|
+
await getFs().mkdir(path);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* @internal
|
|
1082
|
+
* @noRailsEquivalent PERMANENT
|
|
1083
|
+
*/
|
|
1084
|
+
static async fuEachSrcDest0Async(src, dest, yieldFn, targetDirectory = true) {
|
|
1085
|
+
if (Array.isArray(src)) {
|
|
1086
|
+
for (const s of src) {
|
|
1087
|
+
await yieldFn(s, targetDirectory ? getPath().join(dest, getPath().basename(s)) : dest);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
else {
|
|
1091
|
+
if (targetDirectory && (await File.isDirectoryAsync(dest))) {
|
|
1092
|
+
await yieldFn(src, getPath().join(dest, getPath().basename(src)));
|
|
1093
|
+
}
|
|
1094
|
+
else {
|
|
1095
|
+
await yieldFn(src, dest);
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* @internal
|
|
1101
|
+
* @noRailsEquivalent PERMANENT
|
|
1102
|
+
*/
|
|
1103
|
+
static async fuEachSrcDestAsync(src, dest, yieldFn) {
|
|
1104
|
+
await FileUtils.fuEachSrcDest0Async(src, dest, async (s, d) => {
|
|
1105
|
+
if (await File.isIdenticalAsync(s, d))
|
|
1106
|
+
throw new ArgumentError(`same file: ${s} and ${d}`);
|
|
1107
|
+
await yieldFn(s, d);
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
/** @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils.ln` (`vendor/ruby/v3.3.11/lib/fileutils.rb:516-523`), over the backend's async `link`. */
|
|
1111
|
+
static async lnAsync(src, dest, { force, noop, verbose } = {}) {
|
|
1112
|
+
if (rtest(verbose))
|
|
1113
|
+
fuOutputMessage(`ln${rtest(force) ? " -f" : ""} ${[src, dest].flat().join(" ")}`);
|
|
1114
|
+
if (rtest(noop))
|
|
1115
|
+
return;
|
|
1116
|
+
await FileUtils.fuEachSrcDest0Async(src, dest, async (s, d) => {
|
|
1117
|
+
if (rtest(force))
|
|
1118
|
+
await FileUtils.removeFileAsync(d, true);
|
|
1119
|
+
await File.linkAsync(s, d);
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1123
|
+
static linkAsync = FileUtils.lnAsync;
|
|
1124
|
+
/** `FileUtils.ln_s` (`vendor/ruby/v3.3.11/lib/fileutils.rb:706-716`).
|
|
1125
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1126
|
+
*/
|
|
1127
|
+
static async lnSAsync(src, dest, { force, relative = false, noop, verbose, } = {}) {
|
|
1128
|
+
if (rtest(relative)) {
|
|
1129
|
+
return FileUtils.lnSrAsync(src, dest, { force, noop, verbose });
|
|
1130
|
+
}
|
|
1131
|
+
if (rtest(verbose))
|
|
1132
|
+
fuOutputMessage(`ln -s${rtest(force) ? "f" : ""} ${[src, dest].flat().join(" ")}`);
|
|
1133
|
+
if (rtest(noop))
|
|
1134
|
+
return;
|
|
1135
|
+
await FileUtils.fuEachSrcDest0Async(src, dest, async (s, d) => {
|
|
1136
|
+
if (rtest(force))
|
|
1137
|
+
await FileUtils.removeFileAsync(d, true);
|
|
1138
|
+
await File.symlinkAsync(s, d);
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1142
|
+
static symlinkAsync = FileUtils.lnSAsync;
|
|
1143
|
+
/** `FileUtils.ln_sf` (`vendor/ruby/v3.3.11/lib/fileutils.rb:724-726`).
|
|
1144
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1145
|
+
*/
|
|
1146
|
+
static async lnSfAsync(src, dest, { noop, verbose } = {}) {
|
|
1147
|
+
return FileUtils.lnSAsync(src, dest, { force: true, noop, verbose });
|
|
1148
|
+
}
|
|
1149
|
+
/** `FileUtils.ln_sr` (`vendor/ruby/v3.3.11/lib/fileutils.rb:731-768`).
|
|
1150
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1151
|
+
*/
|
|
1152
|
+
static async lnSrAsync(src, dest, { targetDirectory = true, force, noop, verbose, } = {}) {
|
|
1153
|
+
const options = `${rtest(force) ? "f" : ""}${rtest(targetDirectory) ? "" : "T"}`;
|
|
1154
|
+
const srcs = fuList(src);
|
|
1155
|
+
const link = async (s, targetDirP = true) => {
|
|
1156
|
+
const d = rtest(targetDirP) ? File.join(dest, File.basename(s)) : dest;
|
|
1157
|
+
const destdirs = FileUtils.fuSplitPath(await getFs().realpath(rtest(targetDirP) ? dest : File.dirname(dest)));
|
|
1158
|
+
if (FileUtils.isFuStartingPath(s)) {
|
|
1159
|
+
const srcdirs = FileUtils.fuSplitPath(await File.realdirpathAsync(s).catch(() => File.expandPath(s)));
|
|
1160
|
+
const base = FileUtils.fuRelativeComponentsFrom(srcdirs, destdirs);
|
|
1161
|
+
s = File.join(...base);
|
|
1162
|
+
}
|
|
1163
|
+
else {
|
|
1164
|
+
const srcdirs = await FileUtils.fuCleanComponentsAsync(...FileUtils.fuSplitPath(s));
|
|
1165
|
+
const base = FileUtils.fuRelativeComponentsFrom(FileUtils.fuSplitPath(Dir.pwd()), destdirs);
|
|
1166
|
+
while (srcdirs[0] === ".." &&
|
|
1167
|
+
base.length > 0 &&
|
|
1168
|
+
base.at(-1) !== ".." &&
|
|
1169
|
+
!FileUtils.isFuStartingPath(base.at(-1))) {
|
|
1170
|
+
srcdirs.shift();
|
|
1171
|
+
base.pop();
|
|
1172
|
+
}
|
|
1173
|
+
s = File.join(...base, ...srcdirs);
|
|
1174
|
+
}
|
|
1175
|
+
if (rtest(verbose))
|
|
1176
|
+
fuOutputMessage(`ln -s${options} ${s} ${d}`);
|
|
1177
|
+
if (rtest(noop))
|
|
1178
|
+
return;
|
|
1179
|
+
if (rtest(force))
|
|
1180
|
+
await FileUtils.removeFileAsync(d, true);
|
|
1181
|
+
await File.symlinkAsync(s, d);
|
|
1182
|
+
};
|
|
1183
|
+
if (srcs.length === 1) {
|
|
1184
|
+
await link(srcs[0], rtest(targetDirectory) && (await File.isDirectoryAsync(dest)));
|
|
1185
|
+
}
|
|
1186
|
+
else {
|
|
1187
|
+
for (const s of srcs)
|
|
1188
|
+
await link(s);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
/** @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils.cp` (`vendor/ruby/v3.3.11/lib/fileutils.rb:873-879`), over async `readFile` / `writeFile`. */
|
|
1192
|
+
static async cpAsync(src, dest, { preserve, noop, verbose } = {}) {
|
|
1193
|
+
if (rtest(verbose))
|
|
1194
|
+
fuOutputMessage(`cp${rtest(preserve) ? " -p" : ""} ${[src, dest].flat().join(" ")}`);
|
|
1195
|
+
if (rtest(noop))
|
|
1196
|
+
return;
|
|
1197
|
+
await FileUtils.fuEachSrcDestAsync(src, dest, (s, d) => FileUtils.copyFileAsync(s, d, preserve));
|
|
1198
|
+
}
|
|
1199
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1200
|
+
static copyAsync = FileUtils.cpAsync;
|
|
1201
|
+
/** `FileUtils.cp_r` (`vendor/ruby/v3.3.11/lib/fileutils.rb:985-992`).
|
|
1202
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1203
|
+
*/
|
|
1204
|
+
static async cpRAsync(src, dest, { preserve, noop, verbose, dereferenceRoot = true, removeDestination, } = {}) {
|
|
1205
|
+
if (rtest(verbose))
|
|
1206
|
+
fuOutputMessage(`cp -r${rtest(preserve) ? "p" : ""}${removeDestination ? " --remove-destination" : ""} ${[src, dest].flat().join(" ")}`);
|
|
1207
|
+
if (rtest(noop))
|
|
1208
|
+
return;
|
|
1209
|
+
await FileUtils.fuEachSrcDestAsync(src, dest, (s, d) => FileUtils.copyEntryAsync(s, d, preserve, dereferenceRoot, removeDestination));
|
|
1210
|
+
}
|
|
1211
|
+
/** `FileUtils.cp_lr` (`vendor/ruby/v3.3.11/lib/fileutils.rb:627-634`).
|
|
1212
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1213
|
+
*/
|
|
1214
|
+
static async cpLrAsync(src, dest, { noop, verbose, dereferenceRoot = true, removeDestination = false, } = {}) {
|
|
1215
|
+
if (rtest(verbose))
|
|
1216
|
+
fuOutputMessage(`cp -lr${removeDestination ? " --remove-destination" : ""} ${[src, dest].flat().join(" ")}`);
|
|
1217
|
+
if (rtest(noop))
|
|
1218
|
+
return;
|
|
1219
|
+
await FileUtils.fuEachSrcDestAsync(src, dest, (s, d) => FileUtils.linkEntryAsync(s, d, dereferenceRoot, removeDestination));
|
|
1220
|
+
}
|
|
1221
|
+
/** `FileUtils.link_entry` (`vendor/ruby/v3.3.11/lib/fileutils.rb:812-818`).
|
|
1222
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1223
|
+
*/
|
|
1224
|
+
static async linkEntryAsync(src, dest, dereferenceRoot = false, removeDestination = false) {
|
|
1225
|
+
await new Entry_(src, null, dereferenceRoot).preorderTraverseAsync(async (ent) => {
|
|
1226
|
+
const destent = new Entry_(dest, ent.rel, false);
|
|
1227
|
+
if (removeDestination && (await File.isFileAsync(destent.path))) {
|
|
1228
|
+
await File.deleteAsync(destent.path);
|
|
1229
|
+
}
|
|
1230
|
+
await ent.linkAsync(destent.path);
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* `copy_entry` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1040-1053`), whose `wrap_traverse`
|
|
1235
|
+
* walks a directory tree and copies each entry with `Entry_#copy`
|
|
1236
|
+
* (`fileutils.rb:2239-2274`), then its `copy_metadata` under `preserve`.
|
|
1237
|
+
*
|
|
1238
|
+
* `Entry_#copy`'s `socket?` and `pipe?` arms each raise before their copy under
|
|
1239
|
+
* an interpreter that answers no `UNIXServer` (`fileutils.rb:2258-2263`) and no
|
|
1240
|
+
* `File.mkfifo` (`fileutils.rb:2267`); neither constant exists here, so those
|
|
1241
|
+
* are the arms taken.
|
|
1242
|
+
*
|
|
1243
|
+
* `dereference_root` rewrites the root through `File.realpath`
|
|
1244
|
+
* (`fileutils.rb:1041-1043`) so a symlinked root is copied as its target, and
|
|
1245
|
+
* `remove_destination` unlinks an existing destination entry before each copy
|
|
1246
|
+
* (`fileutils.rb:1047`), through `File.delete` — the name Ruby's `File.unlink`
|
|
1247
|
+
* is an alias of (`vendor/ruby/v3.3.11/file.c:3202`).
|
|
1248
|
+
*
|
|
1249
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1250
|
+
*/
|
|
1251
|
+
static copyEntry(src, dest, preserve = false, dereferenceRoot = false, removeDestination = false) {
|
|
1252
|
+
if (dereferenceRoot) {
|
|
1253
|
+
src = File.realpath(src);
|
|
1254
|
+
}
|
|
1255
|
+
new Entry_(src, null, false).wrapTraverse((ent) => {
|
|
1256
|
+
const destent = new Entry_(dest, ent.rel, false);
|
|
1257
|
+
if (removeDestination && (File.isFile(destent.path) || File.isSymlink(destent.path)))
|
|
1258
|
+
File.delete(destent.path);
|
|
1259
|
+
ent.copy(destent.path);
|
|
1260
|
+
}, (ent) => {
|
|
1261
|
+
const destent = new Entry_(dest, ent.rel, false);
|
|
1262
|
+
if (preserve)
|
|
1263
|
+
ent.copyMetadata(destent.path);
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1267
|
+
static async copyEntryAsync(src, dest, preserve = false, dereferenceRoot = false, removeDestination = false) {
|
|
1268
|
+
if (dereferenceRoot) {
|
|
1269
|
+
src = await getFs().realpath(src);
|
|
1270
|
+
}
|
|
1271
|
+
await new Entry_(src, null, false).wrapTraverseAsync(async (ent) => {
|
|
1272
|
+
const destent = new Entry_(dest, ent.rel, false);
|
|
1273
|
+
if (removeDestination &&
|
|
1274
|
+
((await destent.isFileAsync()) || (await destent.isSymlinkAsync())))
|
|
1275
|
+
await File.deleteAsync(destent.path);
|
|
1276
|
+
await ent.copyAsync(destent.path);
|
|
1277
|
+
}, async (ent) => {
|
|
1278
|
+
const destent = new Entry_(dest, ent.rel, false);
|
|
1279
|
+
if (rtest(preserve))
|
|
1280
|
+
await ent.copyMetadataAsync(destent.path);
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
/** `FileUtils.copy_file` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1076-1080`), whose
|
|
1284
|
+
* `Entry_#copy_file` (`fileutils.rb:2277-2283`) copies the bytes and
|
|
1285
|
+
* `copy_metadata` (`fileutils.rb:2285-2312`) the timestamps, ownership and
|
|
1286
|
+
* mode. Ruby's `dereference` reaches only `Entry_#lstat`
|
|
1287
|
+
* (`fileutils.rb:2192-2198`), which `copy_metadata` calls, so it selects an
|
|
1288
|
+
* arm under `preserve` alone and only for a symlink source.
|
|
1289
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1290
|
+
*/
|
|
1291
|
+
static copyFile(src, dest, preserve = false, dereference = true) {
|
|
1292
|
+
const ent = new Entry_(rbGetPath(src), null, dereference);
|
|
1293
|
+
ent.copyFile(dest);
|
|
1294
|
+
if (preserve)
|
|
1295
|
+
ent.copyMetadata(dest);
|
|
1296
|
+
}
|
|
1297
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1298
|
+
static async copyFileAsync(src, dest, preserve = false, dereference = true) {
|
|
1299
|
+
const ent = new Entry_(src, null, dereference);
|
|
1300
|
+
await ent.copyFileAsync(dest);
|
|
1301
|
+
if (rtest(preserve))
|
|
1302
|
+
await ent.copyMetadataAsync(dest);
|
|
1303
|
+
}
|
|
1304
|
+
/** `FileUtils.mv` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1157-1183`). Ruby's `secure:`
|
|
1305
|
+
* kwarg routes the cross-device fallback's teardown through
|
|
1306
|
+
* `remove_entry_secure` (`fileutils.rb:1351-1447`), which is built on
|
|
1307
|
+
* `Process.euid`; `process.*` is unavailable here, so the kwarg has no arm to
|
|
1308
|
+
* select and is not accepted.
|
|
1309
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1310
|
+
*/
|
|
1311
|
+
static mv(src, dest, { force, noop, verbose } = {}) {
|
|
1312
|
+
if (verbose === true)
|
|
1313
|
+
fuOutputMessage(`mv${force === true ? " -f" : ""} ${[src, dest].flat().join(" ")}`);
|
|
1314
|
+
if (noop === true)
|
|
1315
|
+
return;
|
|
1316
|
+
fuEachSrcDest(src, dest, (s, d) => {
|
|
1317
|
+
try {
|
|
1318
|
+
const destent = statOrNull(d);
|
|
1319
|
+
if (destent) {
|
|
1320
|
+
if (destent.isDirectory())
|
|
1321
|
+
throw errnoEexist(d);
|
|
1322
|
+
}
|
|
1323
|
+
try {
|
|
1324
|
+
getFs().renameSync(s, d);
|
|
1325
|
+
}
|
|
1326
|
+
catch (error) {
|
|
1327
|
+
const code = error.code;
|
|
1328
|
+
if (code !== "EXDEV" && code !== "EPERM")
|
|
1329
|
+
throw error;
|
|
1330
|
+
FileUtils.copyEntry(s, d, true);
|
|
1331
|
+
FileUtils.removeEntry(s, force);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
catch (error) {
|
|
1335
|
+
if (!isSystemCallError(error) || force !== true)
|
|
1336
|
+
throw error;
|
|
1337
|
+
}
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1341
|
+
static async mvAsync(src, dest, { force, noop, verbose } = {}) {
|
|
1342
|
+
if (rtest(verbose))
|
|
1343
|
+
fuOutputMessage(`mv${rtest(force) ? " -f" : ""} ${[src, dest].flat().join(" ")}`);
|
|
1344
|
+
if (rtest(noop))
|
|
1345
|
+
return;
|
|
1346
|
+
await FileUtils.fuEachSrcDestAsync(src, dest, async (s, d) => {
|
|
1347
|
+
const destent = new Entry_(d, null, true);
|
|
1348
|
+
try {
|
|
1349
|
+
if ((await destent.lstatBangAsync()) != null) {
|
|
1350
|
+
if (await destent.isDirectoryAsync())
|
|
1351
|
+
throw errnoEexist(d);
|
|
1352
|
+
}
|
|
1353
|
+
try {
|
|
1354
|
+
await getFs().rename(s, d);
|
|
1355
|
+
}
|
|
1356
|
+
catch (error) {
|
|
1357
|
+
const code = error.code;
|
|
1358
|
+
if (code !== "EXDEV" && code !== "EPERM")
|
|
1359
|
+
throw error;
|
|
1360
|
+
await FileUtils.copyEntryAsync(s, d, true);
|
|
1361
|
+
await FileUtils.removeEntryAsync(s, force);
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
catch (error) {
|
|
1365
|
+
if (!isSystemCallError(error) || !rtest(force))
|
|
1366
|
+
throw error;
|
|
1367
|
+
}
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1371
|
+
static moveAsync = FileUtils.mvAsync;
|
|
1372
|
+
/** `FileUtils.rm` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1216-1225`).
|
|
1373
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1374
|
+
*/
|
|
1375
|
+
static rm(list, { force, noop, verbose } = {}) {
|
|
1376
|
+
list = fuList(list);
|
|
1377
|
+
if (verbose === true)
|
|
1378
|
+
fuOutputMessage(`rm${force === true ? " -f" : ""} ${list.join(" ")}`);
|
|
1379
|
+
if (noop === true)
|
|
1380
|
+
return;
|
|
1381
|
+
for (const path of list) {
|
|
1382
|
+
FileUtils.removeFile(path, force);
|
|
1383
|
+
}
|
|
1384
|
+
return list;
|
|
1385
|
+
}
|
|
1386
|
+
/** `FileUtils.rm_f` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1241-1243`).
|
|
1387
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1388
|
+
*/
|
|
1389
|
+
static rmF(list, { noop, verbose } = {}) {
|
|
1390
|
+
return FileUtils.rm(list, { force: true, noop, verbose });
|
|
1391
|
+
}
|
|
1392
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1393
|
+
static async rmAsync(list, { force, noop, verbose } = {}) {
|
|
1394
|
+
list = fuList(list);
|
|
1395
|
+
if (rtest(verbose))
|
|
1396
|
+
fuOutputMessage(`rm${rtest(force) ? " -f" : ""} ${list.join(" ")}`);
|
|
1397
|
+
if (rtest(noop))
|
|
1398
|
+
return;
|
|
1399
|
+
for (const path of list) {
|
|
1400
|
+
await FileUtils.removeFileAsync(path, force);
|
|
1401
|
+
}
|
|
1402
|
+
return list;
|
|
1403
|
+
}
|
|
1404
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1405
|
+
static removeAsync = FileUtils.rmAsync;
|
|
1406
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1407
|
+
static async rmFAsync(list, { noop, verbose } = {}) {
|
|
1408
|
+
return FileUtils.rmAsync(list, { force: true, noop, verbose });
|
|
1409
|
+
}
|
|
1410
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1411
|
+
static safeUnlinkAsync = FileUtils.rmFAsync;
|
|
1412
|
+
/** `FileUtils.rm_r` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1299-1310`).
|
|
1413
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1414
|
+
*/
|
|
1415
|
+
static rmR(list, { force, noop, verbose } = {}) {
|
|
1416
|
+
list = fuList(list);
|
|
1417
|
+
if (verbose === true)
|
|
1418
|
+
fuOutputMessage(`rm -r${force === true ? "f" : ""} ${list.join(" ")}`);
|
|
1419
|
+
if (noop === true)
|
|
1420
|
+
return;
|
|
1421
|
+
for (const path of list) {
|
|
1422
|
+
FileUtils.removeEntry(path, force);
|
|
1423
|
+
}
|
|
1424
|
+
return list;
|
|
1425
|
+
}
|
|
1426
|
+
/** `FileUtils.rm_rf` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1328-1330`). Ruby's
|
|
1427
|
+
* `secure:` kwarg routes `rm_r` through `remove_entry_secure`
|
|
1428
|
+
* (`fileutils.rb:1351-1447`), which is unported, so the kwarg has no arm to
|
|
1429
|
+
* select and is not accepted — as on `rm_r` itself.
|
|
1430
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1431
|
+
*/
|
|
1432
|
+
static rmRf(list, { noop, verbose } = {}) {
|
|
1433
|
+
return FileUtils.rmR(list, { force: true, noop, verbose });
|
|
1434
|
+
}
|
|
1435
|
+
/** `FileUtils.remove_entry` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1449-1456`).
|
|
1436
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1437
|
+
*/
|
|
1438
|
+
static removeEntry(path, force = false) {
|
|
1439
|
+
try {
|
|
1440
|
+
new Entry_(path).postorderTraverse((ent) => {
|
|
1441
|
+
try {
|
|
1442
|
+
ent.remove();
|
|
1443
|
+
}
|
|
1444
|
+
catch (error) {
|
|
1445
|
+
if (force !== true)
|
|
1446
|
+
throw error;
|
|
1447
|
+
}
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
catch (error) {
|
|
1451
|
+
if (force !== true)
|
|
1452
|
+
throw error;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
/** {@link FileUtils.rmR} over the backend's async verbs
|
|
1456
|
+
* (`vendor/ruby/v3.3.11/lib/fileutils.rb:1299-1310`).
|
|
1457
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1458
|
+
*/
|
|
1459
|
+
static async rmRAsync(list, { force, noop, verbose } = {}) {
|
|
1460
|
+
list = fuList(list);
|
|
1461
|
+
if (rtest(verbose))
|
|
1462
|
+
fuOutputMessage(`rm -r${rtest(force) ? "f" : ""} ${list.join(" ")}`);
|
|
1463
|
+
if (rtest(noop))
|
|
1464
|
+
return;
|
|
1465
|
+
for (const path of list) {
|
|
1466
|
+
await FileUtils.removeEntryAsync(path, force);
|
|
1467
|
+
}
|
|
1468
|
+
return list;
|
|
1469
|
+
}
|
|
1470
|
+
/** {@link FileUtils.rmRf} over the backend's async verbs
|
|
1471
|
+
* (`vendor/ruby/v3.3.11/lib/fileutils.rb:1328-1330`).
|
|
1472
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1473
|
+
*/
|
|
1474
|
+
static async rmRfAsync(list, { noop, verbose } = {}) {
|
|
1475
|
+
return FileUtils.rmRAsync(list, { force: true, noop, verbose });
|
|
1476
|
+
}
|
|
1477
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1478
|
+
static rmtreeAsync = FileUtils.rmRfAsync;
|
|
1479
|
+
/** {@link FileUtils.removeEntry} (`vendor/ruby/v3.3.11/lib/fileutils.rb:1449-1456`)
|
|
1480
|
+
* over `Entry_`'s async walk: `Entry_#postorder_traverse`
|
|
1481
|
+
* (`fileutils.rb:2364-2382`) yielding to `Entry_#remove` (`fileutils.rb:2314-2332`).
|
|
1482
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1483
|
+
*/
|
|
1484
|
+
static async removeEntryAsync(path, force = false) {
|
|
1485
|
+
try {
|
|
1486
|
+
await new Entry_(path).postorderTraverseAsync(async (ent) => {
|
|
1487
|
+
try {
|
|
1488
|
+
await ent.removeAsync();
|
|
1489
|
+
}
|
|
1490
|
+
catch (error) {
|
|
1491
|
+
if (!rtest(force))
|
|
1492
|
+
throw error;
|
|
1493
|
+
}
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1496
|
+
catch (error) {
|
|
1497
|
+
if (!rtest(force))
|
|
1498
|
+
throw error;
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
/** `FileUtils.compare_file` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1507-1514`).
|
|
1502
|
+
* @noRailsEquivalent PERMANENT
|
|
1503
|
+
*/
|
|
1504
|
+
static async compareFileAsync(a, b) {
|
|
1505
|
+
const fs = getFs();
|
|
1506
|
+
if ((await fs.stat(a)).size !== (await fs.stat(b)).size)
|
|
1507
|
+
return false;
|
|
1508
|
+
const fa = await fs.openHandle(a, "r");
|
|
1509
|
+
try {
|
|
1510
|
+
const fb = await fs.openHandle(b, "r");
|
|
1511
|
+
try {
|
|
1512
|
+
return await FileUtils.compareStreamAsync(fa, fb);
|
|
1513
|
+
}
|
|
1514
|
+
finally {
|
|
1515
|
+
await fb.close();
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
finally {
|
|
1519
|
+
await fa.close();
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1523
|
+
static isIdenticalAsync = FileUtils.compareFileAsync;
|
|
1524
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1525
|
+
static cmpAsync = FileUtils.compareFileAsync;
|
|
1526
|
+
/** `FileUtils.compare_stream` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1530-1542`).
|
|
1527
|
+
* @noRailsEquivalent PERMANENT
|
|
1528
|
+
*/
|
|
1529
|
+
static compareStream(a, b) {
|
|
1530
|
+
const bsize = FileUtils.fuStreamBlksize(a, b);
|
|
1531
|
+
let sa;
|
|
1532
|
+
let sb;
|
|
1533
|
+
do {
|
|
1534
|
+
sa = a.read(bsize) ?? new Uint8Array(0);
|
|
1535
|
+
sb = b.read(bsize) ?? new Uint8Array(0);
|
|
1536
|
+
if (sa.length === 0 && sb.length === 0)
|
|
1537
|
+
return true;
|
|
1538
|
+
} while (sa.length === sb.length && sa.every((byte, i) => byte === sb[i]));
|
|
1539
|
+
return false;
|
|
1540
|
+
}
|
|
1541
|
+
/** `FileUtils.compare_stream` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1530-1542`) over handles.
|
|
1542
|
+
* @noRailsEquivalent PERMANENT
|
|
1543
|
+
*/
|
|
1544
|
+
static async compareStreamAsync(a, b) {
|
|
1545
|
+
const bsize = FileUtils.fuBlksize(await a.stat()) ??
|
|
1546
|
+
FileUtils.fuBlksize(await b.stat()) ??
|
|
1547
|
+
FileUtils.fuDefaultBlksize();
|
|
1548
|
+
const read = async (s) => {
|
|
1549
|
+
const buffer = new Uint8Array(bsize);
|
|
1550
|
+
let size = 0;
|
|
1551
|
+
while (size < bsize) {
|
|
1552
|
+
const { bytesRead } = await s.read(buffer, size, bsize - size, null);
|
|
1553
|
+
if (bytesRead === 0)
|
|
1554
|
+
break;
|
|
1555
|
+
size += bytesRead;
|
|
1556
|
+
}
|
|
1557
|
+
return buffer.subarray(0, size);
|
|
1558
|
+
};
|
|
1559
|
+
let sa;
|
|
1560
|
+
let sb;
|
|
1561
|
+
do {
|
|
1562
|
+
sa = await read(a);
|
|
1563
|
+
sb = await read(b);
|
|
1564
|
+
if (sa.length === 0 && sb.length === 0)
|
|
1565
|
+
return true;
|
|
1566
|
+
} while (sa.length === sb.length && sa.every((byte, i) => byte === sb[i]));
|
|
1567
|
+
return false;
|
|
1568
|
+
}
|
|
1569
|
+
/** `fu_stream_blksize` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2045-2052`).
|
|
1570
|
+
* @noRailsEquivalent PERMANENT
|
|
1571
|
+
*/
|
|
1572
|
+
static fuStreamBlksize(...streams) {
|
|
1573
|
+
for (const s of streams) {
|
|
1574
|
+
if (!rbObjRespondTo(s, "stat"))
|
|
1575
|
+
continue;
|
|
1576
|
+
const size = FileUtils.fuBlksize(s.stat());
|
|
1577
|
+
if (size != null)
|
|
1578
|
+
return size;
|
|
1579
|
+
}
|
|
1580
|
+
return FileUtils.fuDefaultBlksize();
|
|
1581
|
+
}
|
|
1582
|
+
/** `fu_blksize` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2054-2059`).
|
|
1583
|
+
* @noRailsEquivalent PERMANENT
|
|
1584
|
+
*/
|
|
1585
|
+
static fuBlksize(st) {
|
|
1586
|
+
const s = st.blksize;
|
|
1587
|
+
if (s == null)
|
|
1588
|
+
return null;
|
|
1589
|
+
if (s === 0)
|
|
1590
|
+
return null;
|
|
1591
|
+
return s;
|
|
1592
|
+
}
|
|
1593
|
+
/** `fu_default_blksize` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2061-2063`).
|
|
1594
|
+
* @noRailsEquivalent PERMANENT
|
|
1595
|
+
*/
|
|
1596
|
+
static fuDefaultBlksize() {
|
|
1597
|
+
return 1024;
|
|
1598
|
+
}
|
|
1599
|
+
/** `FileUtils.install` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1609-1639`).
|
|
1600
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1601
|
+
*/
|
|
1602
|
+
static async installAsync(src, dest, { mode, owner, group, preserve, noop, verbose, } = {}) {
|
|
1603
|
+
if (rtest(verbose)) {
|
|
1604
|
+
let msg = "install -c";
|
|
1605
|
+
if (rtest(preserve))
|
|
1606
|
+
msg += " -p";
|
|
1607
|
+
if (mode != null)
|
|
1608
|
+
msg += ` -m ${FileUtils.modeToS(mode)}`;
|
|
1609
|
+
if (owner != null)
|
|
1610
|
+
msg += ` -o ${owner}`;
|
|
1611
|
+
if (group != null)
|
|
1612
|
+
msg += ` -g ${group}`;
|
|
1613
|
+
msg += ` ${[src, dest].flat().join(" ")}`;
|
|
1614
|
+
fuOutputMessage(msg);
|
|
1615
|
+
}
|
|
1616
|
+
if (rtest(noop))
|
|
1617
|
+
return;
|
|
1618
|
+
const uid = await FileUtils.fuGetUidAsync(owner);
|
|
1619
|
+
const gid = await FileUtils.fuGetGidAsync(group);
|
|
1620
|
+
await FileUtils.fuEachSrcDestAsync(src, dest, async (s, d) => {
|
|
1621
|
+
const st = await getFs().stat(s);
|
|
1622
|
+
if (!((await File.isExistAsync(d)) && (await FileUtils.compareFileAsync(s, d)))) {
|
|
1623
|
+
await FileUtils.removeFileAsync(d, true);
|
|
1624
|
+
if (d.endsWith("/")) {
|
|
1625
|
+
await FileUtils.mkdirPAsync(d);
|
|
1626
|
+
await FileUtils.copyFileAsync(s, d + File.basename(s));
|
|
1627
|
+
}
|
|
1628
|
+
else {
|
|
1629
|
+
await FileUtils.mkdirPAsync(File.expandPath("..", d));
|
|
1630
|
+
await FileUtils.copyFileAsync(s, d);
|
|
1631
|
+
}
|
|
1632
|
+
if (rtest(preserve))
|
|
1633
|
+
await File.utimeAsync(st.atime, st.mtime, d);
|
|
1634
|
+
if (mode != null)
|
|
1635
|
+
await File.chmodAsync(await FileUtils.fuModeAsync(mode, st), d);
|
|
1636
|
+
if (uid != null || gid != null)
|
|
1637
|
+
await File.chownAsync(uid, gid, d);
|
|
1638
|
+
}
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1641
|
+
/** `FileUtils.chmod` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1803-1810`).
|
|
1642
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1643
|
+
*/
|
|
1644
|
+
static async chmodAsync(mode, list, { noop, verbose } = {}) {
|
|
1645
|
+
list = fuList(list);
|
|
1646
|
+
if (rtest(verbose))
|
|
1647
|
+
fuOutputMessage(`chmod ${FileUtils.modeToS(mode)} ${list.join(" ")}`);
|
|
1648
|
+
if (rtest(noop))
|
|
1649
|
+
return;
|
|
1650
|
+
for (const path of list) {
|
|
1651
|
+
await new Entry_(path).chmodAsync(await FileUtils.fuModeAsync(mode, path));
|
|
1652
|
+
}
|
|
1653
|
+
return list;
|
|
1654
|
+
}
|
|
1655
|
+
/** `FileUtils.chmod_R` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1815-1830`) over
|
|
1656
|
+
* `Entry_`'s async walk: `Entry_#traverse` (`fileutils.rb:2354-2362`)
|
|
1657
|
+
* yielding to `Entry_#chmod` (`fileutils.rb:2206-2213`).
|
|
1658
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1659
|
+
*/
|
|
1660
|
+
static async chmodRAsync(mode, list, { noop, verbose, force } = {}) {
|
|
1661
|
+
list = fuList(list);
|
|
1662
|
+
if (rtest(verbose))
|
|
1663
|
+
fuOutputMessage(`chmod -R${rtest(force) ? "f" : ""} ${FileUtils.modeToS(mode)} ${list.join(" ")}`);
|
|
1664
|
+
if (rtest(noop))
|
|
1665
|
+
return;
|
|
1666
|
+
for (const root of list) {
|
|
1667
|
+
await new Entry_(root).preorderTraverseAsync(async (ent) => {
|
|
1668
|
+
try {
|
|
1669
|
+
await ent.chmodAsync(await FileUtils.fuModeAsync(mode, ent.path));
|
|
1670
|
+
}
|
|
1671
|
+
catch (error) {
|
|
1672
|
+
if (!rtest(force))
|
|
1673
|
+
throw error;
|
|
1674
|
+
}
|
|
1675
|
+
});
|
|
1676
|
+
}
|
|
1677
|
+
return list;
|
|
1678
|
+
}
|
|
1679
|
+
/** `FileUtils.chown` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1896-1907`).
|
|
1680
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1681
|
+
*/
|
|
1682
|
+
static async chownAsync(user, group, list, { noop, verbose } = {}) {
|
|
1683
|
+
list = fuList(list);
|
|
1684
|
+
if (rtest(verbose))
|
|
1685
|
+
fuOutputMessage(`chown ${group != null ? `${user ?? ""}:${group}` : (user ?? ":")} ${list.join(" ")}`);
|
|
1686
|
+
if (rtest(noop))
|
|
1687
|
+
return;
|
|
1688
|
+
const uid = await FileUtils.fuGetUidAsync(user);
|
|
1689
|
+
const gid = await FileUtils.fuGetGidAsync(group);
|
|
1690
|
+
for (const path of list) {
|
|
1691
|
+
await new Entry_(path).chownAsync(uid, gid);
|
|
1692
|
+
}
|
|
1693
|
+
return list;
|
|
1694
|
+
}
|
|
1695
|
+
/** `FileUtils.chown_R` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1912-1929`).
|
|
1696
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1697
|
+
*/
|
|
1698
|
+
static async chownRAsync(user, group, list, { noop, verbose, force } = {}) {
|
|
1699
|
+
list = fuList(list);
|
|
1700
|
+
if (rtest(verbose))
|
|
1701
|
+
fuOutputMessage(`chown -R${rtest(force) ? "f" : ""} ${group != null ? `${user ?? ""}:${group}` : (user ?? ":")} ${list.join(" ")}`);
|
|
1702
|
+
if (rtest(noop))
|
|
1703
|
+
return;
|
|
1704
|
+
const uid = await FileUtils.fuGetUidAsync(user);
|
|
1705
|
+
const gid = await FileUtils.fuGetGidAsync(group);
|
|
1706
|
+
for (const root of list) {
|
|
1707
|
+
await new Entry_(root).preorderTraverseAsync(async (ent) => {
|
|
1708
|
+
try {
|
|
1709
|
+
await ent.chownAsync(uid, gid);
|
|
1710
|
+
}
|
|
1711
|
+
catch (error) {
|
|
1712
|
+
if (!rtest(force))
|
|
1713
|
+
throw error;
|
|
1714
|
+
}
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
return list;
|
|
1718
|
+
}
|
|
1719
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1720
|
+
static async removeFileAsync(path, force = false) {
|
|
1721
|
+
try {
|
|
1722
|
+
await new Entry_(path).removeFileAsync();
|
|
1723
|
+
}
|
|
1724
|
+
catch (error) {
|
|
1725
|
+
if (!rtest(force))
|
|
1726
|
+
throw error;
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
/** `FileUtils.remove_file` (`vendor/ruby/v3.3.11/lib/fileutils.rb:1473-1477`).
|
|
1730
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1731
|
+
*/
|
|
1732
|
+
static removeFile(path, force = false) {
|
|
1733
|
+
try {
|
|
1734
|
+
new Entry_(path).removeFile();
|
|
1735
|
+
}
|
|
1736
|
+
catch (error) {
|
|
1737
|
+
if (force !== true)
|
|
1738
|
+
throw error;
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
/** `FileUtils.touch` (`vendor/ruby/v3.3.11/lib/fileutils.rb:2006-2026`). The verbose
|
|
1742
|
+
* line's `t.strftime('-t %Y%m%d%H%M.%S ')` is spelled out digit by digit:
|
|
1743
|
+
* `strftime` lives in `@blazetrails/activesupport`, which this leaf cannot
|
|
1744
|
+
* import.
|
|
1745
|
+
* @noRailsEquivalent PERMANENT — Ruby stdlib `FileUtils` module function.
|
|
1746
|
+
*/
|
|
1747
|
+
static touch(list, { noop, mtime, nocreate, verbose, } = {}) {
|
|
1748
|
+
list = fuList(list);
|
|
1749
|
+
const t = mtime;
|
|
1750
|
+
if (verbose === true) {
|
|
1751
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
1752
|
+
const at = t != null
|
|
1753
|
+
? `-t ${t.getFullYear()}${pad(t.getMonth() + 1)}${pad(t.getDate())}` +
|
|
1754
|
+
`${pad(t.getHours())}${pad(t.getMinutes())}.${pad(t.getSeconds())} `
|
|
1755
|
+
: "";
|
|
1756
|
+
fuOutputMessage(`touch ${nocreate === true ? "-c " : ""}${at}${list.join(" ")}`);
|
|
1757
|
+
}
|
|
1758
|
+
if (noop === true)
|
|
1759
|
+
return;
|
|
1760
|
+
for (const path of list) {
|
|
1761
|
+
let created = nocreate;
|
|
1762
|
+
for (;;) {
|
|
1763
|
+
try {
|
|
1764
|
+
fileUtime(t ?? new Date(), t ?? new Date(), path);
|
|
1765
|
+
}
|
|
1766
|
+
catch (error) {
|
|
1767
|
+
if (error.code !== "ENOENT")
|
|
1768
|
+
throw error;
|
|
1769
|
+
if (created === true)
|
|
1770
|
+
throw error;
|
|
1771
|
+
getFs().appendFileSync(path, "");
|
|
1772
|
+
created = true;
|
|
1773
|
+
if (t != null)
|
|
1774
|
+
continue;
|
|
1775
|
+
}
|
|
1776
|
+
break;
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
/** @noRailsEquivalent PERMANENT */
|
|
1781
|
+
static async touchAsync(list, { noop, mtime, nocreate, verbose, } = {}) {
|
|
1782
|
+
list = fuList(list);
|
|
1783
|
+
const t = mtime;
|
|
1784
|
+
if (rtest(verbose)) {
|
|
1785
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
1786
|
+
const at = t != null
|
|
1787
|
+
? `-t ${t.getFullYear()}${pad(t.getMonth() + 1)}${pad(t.getDate())}` +
|
|
1788
|
+
`${pad(t.getHours())}${pad(t.getMinutes())}.${pad(t.getSeconds())} `
|
|
1789
|
+
: "";
|
|
1790
|
+
fuOutputMessage(`touch ${nocreate === true ? "-c " : ""}${at}${list.join(" ")}`);
|
|
1791
|
+
}
|
|
1792
|
+
if (rtest(noop))
|
|
1793
|
+
return;
|
|
1794
|
+
for (const path of list) {
|
|
1795
|
+
let created = nocreate;
|
|
1796
|
+
for (;;) {
|
|
1797
|
+
try {
|
|
1798
|
+
const now = t ?? new Date();
|
|
1799
|
+
await File.utimeAsync(now, now, path);
|
|
1800
|
+
}
|
|
1801
|
+
catch (error) {
|
|
1802
|
+
if (error.code !== "ENOENT")
|
|
1803
|
+
throw error;
|
|
1804
|
+
if (created === true)
|
|
1805
|
+
throw error;
|
|
1806
|
+
await getFs().writeFile(path, "", { flag: "a" });
|
|
1807
|
+
created = true;
|
|
1808
|
+
if (t != null)
|
|
1809
|
+
continue;
|
|
1810
|
+
}
|
|
1811
|
+
break;
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
static {
|
|
1816
|
+
const proto = FileUtils.prototype;
|
|
1817
|
+
for (const name of Object.getOwnPropertyNames(FileUtils)) {
|
|
1818
|
+
const method = FileUtils[name];
|
|
1819
|
+
if (typeof method === "function")
|
|
1820
|
+
proto[name] = method;
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
//# sourceMappingURL=file-utils.js.map
|