Log and continue on NTFS subtree access errors

This commit is contained in:
Meik
2026-03-16 14:23:53 +01:00
parent f2d1cbb3d8
commit 7f3415c690

View File

@@ -140,43 +140,67 @@ namespace LiamNtfs
scanningDepth = depth; scanningDepth = depth;
return privRequestFoldersListAsync(new DirectoryInfo(rootPath), depth); return privRequestFoldersListAsync(new DirectoryInfo(rootPath), depth);
} }
private List<cNtfsResultBase> privRequestFoldersListAsync(DirectoryInfo rootPath, int depth, cNtfsResultFolder parent = null) private List<cNtfsResultBase> privRequestFoldersListAsync(DirectoryInfo rootPath, int depth, cNtfsResultFolder parent = null)
{ {
ResetError(); ResetError();
List<cNtfsResultBase> folders = new List<cNtfsResultBase>(); var folders = new List<cNtfsResultBase>();
try try
{ {
var res = new List<cNtfsResultBase>();
if (depth == 0) if (depth == 0)
return res; return folders;
DirectoryInfo[] directories;
try try
{ {
foreach (var directory in rootPath.GetDirectories()) directories = rootPath.GetDirectories();
}
catch (Exception E)
{
cLogManager.LogEntry($"Could not enumerate directories under '{rootPath.FullName}': {E.Message}", LogLevels.Warning);
cLogManager.LogException(E, LogLevels.Debug);
return folders;
}
foreach (var directory in directories)
{
cNtfsResultFolder folder;
try
{ {
cNtfsResultFolder folder = new cNtfsResultFolder() folder = new cNtfsResultFolder()
{ {
ID = generateUniquId(directory.FullName), ID = generateUniquId(directory.FullName),
Path = directory.FullName, Path = directory.FullName,
CreatedDate = directory.CreationTimeUtc.ToString("s"), CreatedDate = directory.CreationTimeUtc.ToString("s"),
DisplayName = directory.Name, DisplayName = directory.Name,
Level = scanningDepth - depth+1, Level = scanningDepth - depth + 1,
Parent = parent Parent = parent
}; };
}
catch (Exception E)
{
cLogManager.LogEntry($"Could not read directory metadata for '{directory.FullName}': {E.Message}", LogLevels.Warning);
cLogManager.LogException(E, LogLevels.Debug);
continue;
}
folders.Add(folder); folders.Add(folder);
if (depth > 0) if (depth <= 0)
{ continue;
var result = privRequestFoldersListAsync(directory, depth - 1, folder);
try
{
var result = privRequestFoldersListAsync(directory, depth - 1, folder);
if (result != null && result.Count > 0)
folders.AddRange(result); folders.AddRange(result);
} }
catch (Exception E)
{
cLogManager.LogEntry($"Could not scan subtree '{directory.FullName}': {E.Message}", LogLevels.Warning);
cLogManager.LogException(E, LogLevels.Debug);
} }
} }
catch
{
return new List<cNtfsResultBase>(folders);
}
return new List<cNtfsResultBase>(folders); return folders;
} }
catch (Exception E) catch (Exception E)
{ {