From 2746cb7b89ce009d392a464d080eaf9ab652d1ff Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Sun, 27 Oct 2019 20:28:47 -0700 Subject: [PATCH] During Tab Completion, skip file if can't read file attributes (#10910) --- .../CommandCompletion/CompletionCompleters.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index 828b8c52cf..415471362c 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -4275,10 +4275,17 @@ namespace System.Management.Automation continue; var fileInfo = new FileInfo(entry); - if ((fileInfo.Attributes & FileAttributes.Hidden) != 0) + try { - PSObject wrapper = PSObject.AsPSObject(entry); - psobjs.Add(wrapper); + if ((fileInfo.Attributes & FileAttributes.Hidden) != 0) + { + PSObject wrapper = PSObject.AsPSObject(entry); + psobjs.Add(wrapper); + } + } + catch + { + // do nothing if can't get file attributes } } }