From 1b1858cf09d3ba0f3e4c197cdbbd833141bb705e Mon Sep 17 00:00:00 2001 From: George Fleming Date: Wed, 27 Apr 2016 08:35:01 -0700 Subject: [PATCH] Fix FileNotFoundException --- .../commands/management/Navigation.cs | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs index c986672d1..4d7a30c05 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Navigation.cs @@ -3562,29 +3562,36 @@ namespace Microsoft.PowerShell.Commands } bool shouldRecurse = Recurse; - System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(providerPath); - if (Platform.IsLinux && di != null && (di.Attributes & System.IO.FileAttributes.ReparsePoint) != 0) + bool linuxLink = false; + try { - shouldRecurse = false; - } - else - { - if (!Recurse && hasChildren) + System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(providerPath); + if (Platform.IsLinux && di != null && (di.Attributes & System.IO.FileAttributes.ReparsePoint) != 0) { - // Get the localized prompt string - - string prompt = StringUtil.Format(NavigationResources.RemoveItemWithChildren,resolvedPath.Path); - - // Confirm the user wants to remove all children and the item even if - // they did not specify -recurse - - if (!ShouldContinue (prompt, null, ref yesToAll, ref noToAll)) - { - continue; - } - shouldRecurse = true; + shouldRecurse = false; + linuxLink = true; } } + catch (System.IO.FileNotFoundException) + { + // not a directory + } + + if (!linuxLink && !Recurse && hasChildren) + { + // Get the localized prompt string + + string prompt = StringUtil.Format(NavigationResources.RemoveItemWithChildren,resolvedPath.Path); + + // Confirm the user wants to remove all children and the item even if + // they did not specify -recurse + + if (!ShouldContinue (prompt, null, ref yesToAll, ref noToAll)) + { + continue; + } + shouldRecurse = true; + } // Now do the delete // This calls the internal method since it is more efficient