Skip to content

Commit

Permalink
Automatically create the parent directory for the config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Sep 3, 2024
1 parent e979195 commit 0aedf2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/ronin/recon/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

require 'ronin/core/home'
require 'set'
require 'fileutils'

module Ronin
module Recon
Expand Down Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0aedf2b

Please sign in to comment.