From e21643766a78bdc436a41bef6b0ed2f8a51d8dea Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Mon, 5 Mar 2018 16:04:30 +0100
Subject: [PATCH] Only copy service file if target not yet existing.

In addition, this cleans up the config / status files copying using the
new structure.
---
 Scripts/Install-Service.ps1 | 28 +++++++---------------------
 1 file changed, 7 insertions(+), 21 deletions(-)

diff --git a/Scripts/Install-Service.ps1 b/Scripts/Install-Service.ps1
index 92d943f..013ee8f 100644
--- a/Scripts/Install-Service.ps1
+++ b/Scripts/Install-Service.ps1
@@ -27,32 +27,18 @@ function Start-MyService {
 }
 
 
-function Copy-FileIfNew([string]$SourceFile, [string]$Destination) {
-    # SourceFile is expected to be a FILE name
-    # Destination is expected to be a PATH
-    if (Test-Path "$Destination\$SourceFile") {
-        return
-    }
-    try {
-        Copy-Item -Path $SourceFile -Destination $Destination -ErrorAction Stop
-    }
-    catch {
-        $ex = $_.Exception
-        Write-Host "Copying $($SourceFile) FAILED!" -Fore Red
-        Write-Host $ex.Message
-        Exit
+function Copy-ServiceFiles {
+    if (Test-Path -Type Container $ServiceDir) {
+        Write-Host "Target directory [$($ServiceDir)] exists, stopping!"
+        Exit 1
     }
-}
 
-
-function Copy-ServiceFiles {
     Write-Host -NoNewLine "Updating / installing service files: "
     $TargetDir = New-Item -ItemType Container -Force -Path $ServiceDir
     try {
-        Copy-Item -Recurse -Force -Path "$ServiceName\*" -Destination $ServiceDir -ErrorAction Stop
-        Copy-FileIfNew "configuration.xml" $ServiceDir
-        Copy-FileIfNew "status.xml" $ServiceDir
-        Copy-FileIfNew "service.log" $ServiceLog
+        Copy-Item -Recurse -Force -Path "$ServiceName\*" -Destination $ServiceDir
+        Copy-Item -Recurse -Force -Path "conf-example" -Destination $ServiceDir
+        Copy-Item -Force -Path "$($ServiceName).log" -Destination $ServiceLog
         Clear-Content $ServiceLog
         Write-Host "[OK]" -Fore Green
     }
-- 
GitLab