[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>
Tue, 5 Dec 2023 16:31:16 +0000 (19:31 +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 22b146ad85901b122a214a9f0782a6c3aa5d75a6..9e60badc27705723697444bb413c8d269f7a116b 100644 (file)
@@ -343,7 +343,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))