[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, 19 Nov 2024 14:47:36 +0000 (17:47 +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 28fc7bbaf8c8ae8483dd6881c1fbc49c1df0fc0f..6d38ce2d9e165b0204fcc1cf6807cbc1fb524e78 100644 (file)
@@ -400,7 +400,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))