1- # Plaster zen for file handling. All file related operations should use this method
2- # to actually write/overwrite/modify files in the DestinationPath. This method
3- # handles detecting conflicts, gives the user a chance to determine how to handle
4- # conflicts. The user can choose to use the Force parameter to force the overwriting
5- # of existing files at the destination path.
6- # File processing (expanding substitution variable, modifying file contents) should always
7- # be done to a temp file (be sure to always remove temp file when done). That temp file
8- # is what gets passed to this function as the $SrcPath. This allows Plaster to alert the
9- # user when the repeated application of a template will modify any existing file.
10- # NOTE: Plaster keeps track of which files it has "created" (as opposed to overwritten)
11- # so that any later change to that file doesn't trigger conflict handling.
1+ <#
2+ Plaster zen for file handling. All file related operations should use this
3+ method to actually write/overwrite/modify files in the DestinationPath. This
4+ method handles detecting conflicts, gives the user a chance to determine how to
5+ handle conflicts. The user can choose to use the Force parameter to force the
6+ overwriting of existing files at the destination path. File processing
7+ (expanding substitution variable, modifying file contents) should always be done
8+ to a temp file (be sure to always remove temp file when done). That temp file is
9+ what gets passed to this function as the $SrcPath. This allows Plaster to alert
10+ the user when the repeated application of a template will modify any existing
11+ file.
12+
13+ NOTE: Plaster keeps track of which files it has "created" (as opposed to
14+ overwritten) so that any later change to that file doesn't trigger conflict
15+ handling.
16+ #>
1217function Copy-FileWithConflictDetection {
1318 [CmdletBinding (SupportsShouldProcess = $true )]
1419 param (
@@ -23,7 +28,7 @@ function Copy-FileWithConflictDetection {
2328
2429 # Check if DstPath file conflicts with an existing SrcPath file.
2530 $operation = $LocalizedData.OpCreate
26- $opmessage = ( ConvertTo-DestinationRelativePath $DstPath )
31+ $opMessage = ConvertTo-DestinationRelativePath $DstPath
2732 if (Test-Path - LiteralPath $DstPath ) {
2833 if (Test-FilesIdentical $SrcPath $DstPath ) {
2934 $operation = $LocalizedData.OpIdentical
@@ -40,23 +45,31 @@ function Copy-FileWithConflictDetection {
4045
4146 # Copy the file to the destination
4247 if ($PSCmdlet.ShouldProcess ($DstPath , $operation )) {
43- Write-OperationStatus $operation $opmessage
48+ Write-OperationStatus - Operation $operation - Message $opMessage
4449
4550 if ($operation -eq $LocalizedData.OpIdentical ) {
4651 # If the files are identical, no need to do anything
4752 return
4853 }
4954
50- if (($operation -eq $LocalizedData.OpCreate ) -or ($operation -eq $LocalizedData.OpUpdate )) {
55+ if (
56+ ($operation -eq $LocalizedData.OpCreate ) -or
57+ ($operation -eq $LocalizedData.OpUpdate )
58+ ) {
5159 Copy-Item - LiteralPath $SrcPath - Destination $DstPath
5260 if ($PassThru ) {
5361 $InvokePlasterInfo.CreatedFiles += $DstPath
5462 }
5563 $script :templateCreatedFiles [$DstPath ] = $null
56- } elseif ($Force -or $PSCmdlet.ShouldContinue (($LocalizedData.OverwriteFile_F1 -f $DstPath ),
64+ } elseif (
65+ $Force -or
66+ $PSCmdlet.ShouldContinue (
67+ ($LocalizedData.OverwriteFile_F1 -f $DstPath ),
5768 $LocalizedData.FileConflict ,
5869 [ref ]$script :fileConflictConfirmYesToAll ,
59- [ref ]$script :fileConflictConfirmNoToAll )) {
70+ [ref ]$script :fileConflictConfirmNoToAll
71+ )
72+ ) {
6073 $backupFilename = New-BackupFilename $DstPath
6174 Copy-Item - LiteralPath $DstPath - Destination $backupFilename
6275 Copy-Item - LiteralPath $SrcPath - Destination $DstPath
0 commit comments