Browse Source

fix ./park.ps1 --delete

Daniel Sheffield 2 weeks ago
parent
commit
fd283c6dd0
1 changed files with 15 additions and 7 deletions
  1. 15 7
      park.ps1

+ 15 - 7
park.ps1

@@ -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
+                    }
                 }
             }
         }