Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/psrp/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def copy_file(
dest: str,
*,
expand_variables: bool = False,
overwrite: bool = False,
) -> str:
"""Copies a file to the remote connection.

Expand All @@ -60,6 +61,7 @@ def copy_file(
and relative paths are resolved from the current location of the
connection which is based on the connection type.
expand_variables: Expand the src and dest paths for any variables.
overwrite: Overwrite the destination file.

Returns:
str: The absolute path to the remote destination that the local file
Expand Down Expand Up @@ -94,6 +96,7 @@ def read_buffer(path: pathlib.Path, buffer_size: int) -> t.Iterator[bytes]:
ps.add_parameters(
Path=dest,
ExpandVariables=expand_variables,
Overwrite=overwrite,
)

if log.isEnabledFor(logging.DEBUG):
Expand Down
9 changes: 8 additions & 1 deletion src/psrp/_pwsh/copy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ param (

[Parameter()]
[switch]
$ExpandVariables
$ExpandVariables,

[Parameter()]
[switch]
$Overwrite
)

begin {
Expand All @@ -36,6 +40,9 @@ begin {
if (-not (Test-Path -LiteralPath $parentDir)) {
throw "Target path directory '$parentDir' does not exist"
}
if (-not $overwrite -and (Test-Path -LiteralPath $Path)) {
throw "Target file '$Path' already exists"
}

$bindingFlags = [System.Reflection.BindingFlags]'NonPublic, Instance'
Function Get-Property {
Expand Down