Skip to content

Commit

Permalink
Fix folder UnauthorizedAccessException #1282 #1357
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuJianhua authored and bao-qian committed Apr 11, 2017
1 parent 5640b21 commit 808523b
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions Plugins/Wox.Plugin.Program/Programs/Win32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,25 +204,30 @@ private static Win32 ExeProgram(string path)

private static IEnumerable<string> ProgramPaths(string directory, string[] suffixes)
{
if (Directory.Exists(directory))
if (!Directory.Exists(directory))
return new string[] { };

var ds = Directory.GetDirectories(directory);

var paths = ds.SelectMany(d =>
{
IEnumerable<string> files;
try
{
files = Directory.EnumerateFiles(directory, "*", SearchOption.AllDirectories);
var paths_for_suffixes = suffixes.SelectMany(s =>
{
var pattern = $"*.{s}";
var ps = Directory.EnumerateFiles(d, pattern, SearchOption.AllDirectories);
return ps;
});
return paths_for_suffixes;
}
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
{
Log.Exception($"|Program.Win32.ProgramPaths|Can't parse directory <{directory}>", e);
return new string[] { };
Log.Exception($"|Program.Win32.ProgramPaths|Don't have permission on <{directory}>", e);
return new List<string>();
}
files = files.Where(f => suffixes.Contains(Extension(f)));
return files;
}
else
{
return new string[] { };
}
});
return paths;
}

private static string Extension(string path)
Expand Down

1 comment on commit 808523b

@CrazyCoder
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit breaks indexing of files in certain cases. A lot of results will no longer appear. If I revert this change, everything is back to normal.

Please sign in to comment.