As we know, files cannot be moved across filesystems atomically. In that
case, FileUtils.mv will make a copy. But if we create the temp file in
the same directory as the target, we can avoid this and use File.rename
directly.
Additionally, the rename should be the absolute last step, so that the
original file is preserved if altering ownership and permissions fails.
We need to install the helper module not just on `etc` but also on all
subdirectories of it too. Also, handle the case where we install
a subdirectory with etc.install.
ClosesHomebrew/homebrew#26145.
As far as I can tell these methods have only ever been used in the test
suite.
Since Formula includes FileUtils, it is generally simpler (and in the
case of cp, more readable) to use the FileUtils methods directly.
ClosesHomebrew/homebrew#30081.
Ruby 2.2 will define Pathname#/ as a simple alias of Pathname#+.
In practice, this means that it will raise a TypeError unless the
argument responds to to_path or to_str.
Currently we blindly convert the argument to a string using to_s, so
deprecate this in the interest of matching the upstream behavior. In the
future we can replace this with
alias_method :/, :+ unless method_defined?(:/)
ClosesHomebrew/homebrew#30079.
Pathname#inspect on Ruby 2.0 throws away the encoding of the object's
underlying string and returns a string tagged as ASCII-8BIT.
If you simply write
puts Pathname.new("some string with non-ascii bytes").inspect
no error will be raised, because the implementation of Pathname#inspect
does not call into Object#inspect.
However, if you wrap that pathname object in an array first, then
puts [Pathname.new("some string with non-ascii bytes")].inspect
will raise Encoding::CompatibilityError: "inspected result must be ASCII
only or use the same encoding with default external".
Raising an error in this codepath is new in Ruby 2.0, and this specific
bug is fixed in Ruby 2.1. I've opened a bug upstream:
https://bugs.ruby-lang.org/issues/9915FixesHomebrew/homebrew#29947.
This method is for internal use only. It is unsuitable for use in
formulae, which should use install_symlink to create relative symlinks.
Thus callers are required to pass a Pathname, not a string, and we can
remove this conditional.
Further, if src is not absolute, then src.relative_path_from(dirname)
will fail. All callers currently pass absolute pathnames. Therefore we
don't need to call expand_path when printing it.