Skip to content
Snippets Groups Projects
Commit d8f15941 authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard: Committed by Niko Ehrenfeuchter (adm)
Browse files

Wrap renaming with a try-catch block.

Refers to #13
parent fa5645ce
No related branches found
No related tags found
No related merge requests found
......@@ -105,8 +105,15 @@ function Update-FileIfNewer([string]$SourcePath, [string]$Destination) {
# assemble a timestamp string like "2017-12-04T16.41.35"
$BakTimeStamp = Get-Date -Format s | foreach {$_ -replace ":", "."}
$BakName = "$($SrcFileNoSuffix)_pre-$BakTimeStamp$SrcFileSuffix"
Rename-Item "$DstPath" "$Destination\$BakName"
Log-Info "Creating backup of '$($DstPath)' to '$($BakName)'."
try {
Rename-Item "$DstPath" "$Destination\$BakName" -ErrorAction Stop
}
catch {
$ex = $_.Exception.Message
Log-Error "Backing up '$($DstPath)' as '$($BakName) FAILED!`n$($ex)"
Exit
}
try {
Copy-Item -Path $SourcePath -Destination $Destination -ErrorAction Stop
Log-Info "Updated config file '$($DstPath)'."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment