From 0aedf2b9fa440b0d38d96d980906cdd787237f7c Mon Sep 17 00:00:00 2001 From: Postmodern Date: Tue, 3 Sep 2024 01:01:57 -0700 Subject: [PATCH] Automatically create the parent directory for the config file. --- lib/ronin/recon/config.rb | 2 ++ spec/config_spec.rb | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/ronin/recon/config.rb b/lib/ronin/recon/config.rb index 814fae5..88ec039 100644 --- a/lib/ronin/recon/config.rb +++ b/lib/ronin/recon/config.rb @@ -22,6 +22,7 @@ require 'ronin/core/home' require 'set' +require 'fileutils' module Ronin module Recon @@ -419,6 +420,7 @@ def to_yaml(options={}) # @since 0.2.0 # def save(path=DEFAULT_PATH) + FileUtils.mkdir_p(File.dirname(path)) File.write(path,to_yaml) end diff --git a/spec/config_spec.rb b/spec/config_spec.rb index f88405b..fdcc7c3 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -869,5 +869,15 @@ expect(File.read(path)).to eq(subject.to_yaml) end + + context "when the parent directory does not exist yet" do + let(:path) { File.join(tempdir,'does','not','exist','test-config.yml') } + + it "must create the parent directory" do + subject.save(path) + + expect(File.directory?(File.dirname(path))).to be(true) + end + end end end