diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 57629775d8..02ff1e35b4 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -160,9 +160,16 @@ class Pathname open("a", *open_args) { |f| f.puts(content) } end - # NOTE always overwrites + # NOTE: This always overwrites. def atomic_write(content) + # The enclosing `mktmpdir` and the `chmod` are a workaround + # for https://github.com/rails/rails/pull/34037. Dir.mktmpdir(".d", dirname) do |tmpdir| + begin + FileUtils.chmod "+t", dirname + rescue Errno::EPERM + :ignore + end File.atomic_write(self, tmpdir) do |file| file.write(content) end