From e17fbbfb30da394d6abbb91da4a963ff8913ad47 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 1 Mar 2026 20:23:36 +0200 Subject: fix dry-run crash when parent directory does not exist yet, add rake and rcm fallback to examples --- examples/gem/Gemfile | 1 + examples/plain_ruby/config.rb | 6 +++++- examples/rake/Gemfile | 1 + lib/dslkeywords/file.rb | 13 ++++++++++--- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/examples/gem/Gemfile b/examples/gem/Gemfile index b1f79ad..7e62d34 100644 --- a/examples/gem/Gemfile +++ b/examples/gem/Gemfile @@ -2,3 +2,4 @@ source 'https://rubygems.org' # Point at the local rcm checkout; change to gem 'rcm' once published. gem 'rcm', path: '../../' +gem 'rake' diff --git a/examples/plain_ruby/config.rb b/examples/plain_ruby/config.rb index f49bd01..c730c05 100755 --- a/examples/plain_ruby/config.rb +++ b/examples/plain_ruby/config.rb @@ -8,7 +8,11 @@ # # Requires rcm to be installed as a gem, or adjust the path below: # require_relative '../../lib/dsl' -require 'rcm' +begin + require 'rcm' +rescue LoadError + require_relative '../../lib/dsl' +end configure do # Write a simple text file with static content. diff --git a/examples/rake/Gemfile b/examples/rake/Gemfile index b1f79ad..7e62d34 100644 --- a/examples/rake/Gemfile +++ b/examples/rake/Gemfile @@ -2,3 +2,4 @@ source 'https://rubygems.org' # Point at the local rcm checkout; change to gem 'rcm' once published. gem 'rcm', path: '../../' +gem 'rake' diff --git a/lib/dslkeywords/file.rb b/lib/dslkeywords/file.rb index 9a44f72..927054a 100644 --- a/lib/dslkeywords/file.rb +++ b/lib/dslkeywords/file.rb @@ -211,6 +211,14 @@ module RCM end def write!(text) + # In dry-run mode skip all filesystem access and just report what would + # happen — the parent directory may not exist yet so we cannot write the + # temporary file at all. + if option :dry + info "Writing file #{@file_path} - dry run!" + return + end + tmp_path = "#{@file_path}.rcmtmp" ::File.write(tmp_path, text) @@ -223,9 +231,8 @@ module RCM backup!(@file_path, checksum) # File changed, backup! end - do? "Writing file #{@file_path}" do - ::File.rename(tmp_path, @file_path) - end + info "Writing file #{@file_path}" + ::File.rename(tmp_path, @file_path) ::File.delete(tmp_path) if ::File.file?(tmp_path) end end -- cgit v1.2.3