-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(GH-3286) Add
file::delete()
function
Closes #3286 !feature * **Add `file::delete()` function** Delete a file on localhost using ruby's `File.delete`. This will only delete files on the machine you run Bolt on.
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
# Delete a file on localhost using ruby's `File.delete`. This will only delete | ||
# files on the machine you run Bolt on. | ||
Puppet::Functions.create_function(:'file::delete') do | ||
# @param filename Absolute path. | ||
# @example Delete a file from disk | ||
# file::delete('C:/Users/me/report') | ||
dispatch :delete do | ||
required_param 'String', :filename | ||
return_type 'Undef' | ||
end | ||
|
||
def delete(filename) | ||
# Send Analytics Report | ||
Puppet.lookup(:bolt_executor) {}&.report_function_call(self.class.name) | ||
|
||
File.delete(filename) | ||
nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'tempfile' | ||
|
||
describe 'file::delete' do | ||
it { | ||
Dir.mktmpdir do |dir| | ||
file = File.join(dir, 'file_delete') | ||
File.write(file, 'file_delete_contents') | ||
is_expected.to run.with_params(file) | ||
expect(File.exist?(file)).to eq(false) | ||
end | ||
} | ||
end |