diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-01 20:23:36 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-01 20:23:36 +0200 |
| commit | e17fbbfb30da394d6abbb91da4a963ff8913ad47 (patch) | |
| tree | a25fcbf4e9f6e5c4d1a1b0a763a32f05d9758bcd | |
| parent | 990c817571844462906b4ac7a58e64640be660e2 (diff) | |
fix dry-run crash when parent directory does not exist yet, add rake and rcm fallback to examples
| -rw-r--r-- | examples/gem/Gemfile | 1 | ||||
| -rwxr-xr-x | examples/plain_ruby/config.rb | 6 | ||||
| -rw-r--r-- | examples/rake/Gemfile | 1 | ||||
| -rw-r--r-- | 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 |
