|
@@ -51,13 +51,21 @@ function Is-Under($child, $parent) {
|
|
|
}
|
|
|
|
|
|
if ($Delete -or $Restow) {
|
|
|
- Get-ChildItem -Path $TargetRoot -Recurse -Force | ForEach-Object {
|
|
|
- if ($_.LinkType -eq 'SymbolicLink') {
|
|
|
- $linkTarget = (Get-Item $_.FullName -Force).Target
|
|
|
- if ($linkTarget -and (Is-Under $linkTarget $SourceRoot)) {
|
|
|
- Write-Verbose "Unlinking: $($_.FullName) -> $linkTarget"
|
|
|
- if (-not $Simulate) {
|
|
|
- Remove-Item $_.FullName
|
|
|
+ Get-ChildItem -Path $SourceRoot -Recurse -Force | Where-Object {
|
|
|
+ -not $_.PSIsContainer -or $_.Attributes -match 'ReparsePoint'
|
|
|
+ } | ForEach-Object {
|
|
|
+ $relativePath = $_.FullName.Substring($SourceRoot.Length).TrimStart('\', '/')
|
|
|
+ $targetFile = Join-Path $TargetRoot $relativePath
|
|
|
+ Write-Verbose "$targetFile"
|
|
|
+ if (Test-Path $targetFile){
|
|
|
+ $targetFile = Get-Item $targetFile -Force
|
|
|
+ if ($targetFile.LinkType -eq 'SymbolicLink') {
|
|
|
+ $linkTarget = (Get-Item $targetFile.FullName -Force).Target
|
|
|
+ if ($linkTarget -and (Is-Under $linkTarget $SourceRoot)) {
|
|
|
+ Write-Verbose "Unlinking: $($targetFile.FullName) -> $linkTarget"
|
|
|
+ if (-not $Simulate) {
|
|
|
+ Remove-Item $targetFile.FullName -Force
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|