From 9427e6b29b9bb23a43ac54e77da87889e829ee54 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Wed, 29 Apr 2026 11:37:26 +0200 Subject: [PATCH] Reverse-sync https://github.com/ruby/ruby/commit/01e4a82706a1f07eff874f9043138b75a8575b7c --- templates/template.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/templates/template.rb b/templates/template.rb index 7638c9c058..0fdeda561f 100755 --- a/templates/template.rb +++ b/templates/template.rb @@ -643,8 +643,14 @@ def render(name, write_to: nil) end end - FileUtils.mkdir_p(File.dirname(write_to)) - File.write(write_to, contents) + begin + FileUtils.mkdir_p(File.dirname(write_to)) + File.write(write_to, contents) + rescue SystemCallError # EACCES, EPERM, EROFS, etc. + # Fall back to the current directory + FileUtils.mkdir_p(File.dirname(name)) + File.write(name, contents) + end end private