[Tizen] Fix "dump analyze" access denied related issue.
authorMikhail Kurinnoi <m.kurinnoi@samsung.com>
Tue, 15 Mar 2022 15:00:52 +0000 (08:00 -0700)
committerMikhail Kurinnoi <m.kurinnoi@samsung.com>
Thu, 29 Sep 2022 09:40:48 +0000 (12:40 +0300)
Fix 3cf4501 commit changes, since after 6946f55 commit in upstream, "dotnet analyze" could not open
dump because have "access denied" error to one of subdirectories in directory with dump file.

src/Microsoft.Diagnostics.DebugServices.Implementation/SymbolService.cs

index 0397bbdd2b5f89fac326eecf1039260533c2630f..e69be552eec585eee74615b78a788ef8b8e44a41 100644 (file)
@@ -334,7 +334,26 @@ namespace Microsoft.Diagnostics.DebugServices.Implementation
             if (Directory.Exists(symbolDirectoryPath))
             {
                 // Add all subdirectories.
-                probingPaths.AddRange(Directory.GetDirectories(symbolDirectoryPath, "*", SearchOption.AllDirectories));
+                // Note, for proper result order we use Breadth-first search algorithm here.
+                Queue<string> pathsCheck = new Queue<string>();
+                pathsCheck.Enqueue(symbolDirectoryPath);
+
+                while (pathsCheck.Count > 0)
+                {
+                    string path = pathsCheck.Dequeue();
+                    try
+                    {
+                        // Note, at this line we could have `UnauthorizedAccessException` exception due to SMACK or file access permisions,
+                        // this directory and all its subdirectories must be ignored and not added into `probingPaths` list.
+                        string[] subdirectoryEntries = Directory.GetDirectories(path);
+                        foreach (string subdirectory in subdirectoryEntries)
+                        {
+                            pathsCheck.Enqueue(subdirectory);
+                        }
+                        probingPaths.Add(path);
+                    }
+                    catch (UnauthorizedAccessException) { }
+                }
             }
             // Make sure the root directory is enumerated last so that it comes first in the fallback tree.
             foreach (var path in Enumerable.Reverse(probingPaths))