From 4c5b2e91db41404f6256bbc40113105ab9014d76 Mon Sep 17 00:00:00 2001 From: L2JE Date: Mon, 15 Nov 2021 09:14:16 -0300 Subject: [PATCH 1/3] Delete file if exists before copying --- contents/winrm-filecopier.py | 1 + 1 file changed, 1 insertion(+) diff --git a/contents/winrm-filecopier.py b/contents/winrm-filecopier.py index 40eba4d..073ffca 100644 --- a/contents/winrm-filecopier.py +++ b/contents/winrm-filecopier.py @@ -184,6 +184,7 @@ def winrm_upload(self, print("coping file %s to %s" % (local_path, full_path)) self.session.run_ps('if (!(Test-Path {0})) {{ New-Item -ItemType directory -Path {0} }}'.format(remote_path)) + self.session.run_ps('if ((Test-Path {0})) {{ rm {0} }}'.format(full_path)) size = os.stat(local_path).st_size with open(local_path, 'rb') as f: From 82a3897c3f1955a3f00a4f1f7d64dd4e83088ccb Mon Sep 17 00:00:00 2001 From: L2JE Date: Mon, 15 Nov 2021 09:14:16 -0300 Subject: [PATCH 2/3] Delete file if exists before copying depending on given env variable. Added override config option in plugin.yaml --- contents/winrm-filecopier.py | 13 +++++++++++-- plugin.yaml | 7 +++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/contents/winrm-filecopier.py b/contents/winrm-filecopier.py index 40eba4d..65291de 100644 --- a/contents/winrm-filecopier.py +++ b/contents/winrm-filecopier.py @@ -174,7 +174,8 @@ def winrm_upload(self, remote_filename, local_path, step=2048, - quiet=True): + quiet=True, + override=False): if remote_path.endswith('/') or remote_path.endswith('\\'): full_path = remote_path + remote_filename @@ -184,6 +185,9 @@ def winrm_upload(self, print("coping file %s to %s" % (local_path, full_path)) self.session.run_ps('if (!(Test-Path {0})) {{ New-Item -ItemType directory -Path {0} }}'.format(remote_path)) + + if(override): + self.session.run_ps('if ((Test-Path {0})) {{ rm {0} }}'.format(full_path)) size = os.stat(local_path).st_size with open(local_path, 'rb') as f: @@ -245,6 +249,10 @@ def winrm_upload(self, krb5config = None krbdelegation = False forceTicket = False +override=False + +if os.environ.get('RD_CONFIG_OVERRIDE') == 'true': + override = True if "RD_CONFIG_AUTHTYPE" in os.environ: authentication = os.getenv("RD_CONFIG_AUTHTYPE") @@ -377,7 +385,8 @@ def winrm_upload(self, copy.winrm_upload(remote_path=destination, remote_filename=filename, local_path=args.source, - quiet=quiet) + quiet=quiet, + override=override) else: log.warn("The source is a directory, skipping copy") diff --git a/plugin.yaml b/plugin.yaml index 6dc15c4..89c245f 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -284,6 +284,10 @@ providers: name: debug title: Debug? description: 'Write debug messages' + - type: Boolean + name: override + title: Override? + description: 'Overrides the file on the remote server if it already exists' - name: krb5config title: krb5 Config File description: "Path of krb5.conf file" @@ -409,5 +413,4 @@ providers: default: "false" required: false renderingOptions: - groupName: Kerberos - + groupName: Kerberos \ No newline at end of file From 48a71eeb5e156b277fa315c9e4f84694ab9699b6 Mon Sep 17 00:00:00 2001 From: L2JE Date: Wed, 17 Nov 2021 14:06:57 -0300 Subject: [PATCH 3/3] Delete only if it is a file --- contents/winrm-filecopier.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/winrm-filecopier.py b/contents/winrm-filecopier.py index 55b0d8c..9fd4139 100644 --- a/contents/winrm-filecopier.py +++ b/contents/winrm-filecopier.py @@ -187,7 +187,7 @@ def winrm_upload(self, self.session.run_ps('if (!(Test-Path {0})) {{ New-Item -ItemType directory -Path {0} }}'.format(remote_path)) if(override): - self.session.run_ps('if ((Test-Path {0})) {{ rm {0} }}'.format(full_path)) + self.session.run_ps('if ((Test-Path {0} -PathType Leaf)) {{ rm {0} }}'.format(full_path)) size = os.stat(local_path).st_size with open(local_path, 'rb') as f: