Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring delete_file action #24

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -837,18 +837,20 @@ For best results, the <b>file path</b> parameter should be an absolute path to a
PARAMETER | REQUIRED | DESCRIPTION | TYPE | CONTAINS
--------- | -------- | ----------- | ---- | --------
**ip_hostname** | optional | IP/Hostname | string | `ip` `host name`
**file_path** | required | Path to file | string | `file path`
**file_path** | required | Path to file / directory | string | `file path`
**force** | optional | Use the force flag for delete | boolean |
**recurse** | optional | Use the recurse flag to delete directory content recursively | boolean |

#### Action Output
DATA PATH | TYPE | CONTAINS | EXAMPLE VALUES
--------- | ---- | -------- | --------------
action_result.parameter.file_path | string | `file path` | C:\\Windows\\System32\\notepad.exe
action_result.parameter.force | boolean | | True False
action_result.parameter.recurse | boolean | | True False
action_result.parameter.ip_hostname | string | `ip` `host name` | 8.8.8.8 8.8.8.8\\testphantom.local
action_result.data | string | |
action_result.status | string | | success failed
action_result.message | string | | Successfully deleted files
action_result.summary | string | |
summary.total_objects | numeric | | 1
summary.total_objects_successful | numeric | | 1
summary.total_objects_successful | numeric | | 1
10 changes: 6 additions & 4 deletions winrm_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,11 +995,13 @@ def _handle_delete_file(self, param):
return action_result.get_status()

file_path = self._handle_py_ver_compat_for_input_str(param['file_path'])
force_delete = '-Force ' if param.get('force') else ''
recurse_delete = ' -Recurse' if param.get('recurse') else ''
force_delete = ' -Force' if param.get('force') else ''

ps_script = "& del {0}{1}".format(
force_delete,
self._sanitize_string(file_path)
ps_script = "Remove-Item -Path {0}{1}{2}".format(
self._sanitize_string(file_path),
recurse_delete,
force_delete
)

ret_val = self._run_ps(action_result, ps_script, parse_callback=pc.check_exit_no_data2)
Expand Down
Loading