From 40df80b40f2c0ca6415d811c36b3fea56af516cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Fri, 3 Nov 2023 10:42:30 +0100 Subject: [PATCH] Fix crash on unreadable root drive --- .../RootDriveInfoService.cs | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Providers/FileTime.Providers.Local/RootDriveInfoService.cs b/src/Providers/FileTime.Providers.Local/RootDriveInfoService.cs index bb0d44d..69c655f 100644 --- a/src/Providers/FileTime.Providers.Local/RootDriveInfoService.cs +++ b/src/Providers/FileTime.Providers.Local/RootDriveInfoService.cs @@ -61,14 +61,23 @@ public class RootDriveInfoService : IRootDriveInfoService private (DriveInfo Drive, IContainer? Item) GetContainer(DriveInfo rootDriveInfo) { - var task = Task.Run( - async () => await _localContentProvider.GetItemByNativePathAsync( - new NativePath(rootDriveInfo.RootDirectory.FullName), - PointInTime.Present) - ); - task.Wait(); - - return (rootDriveInfo, task.Result as IContainer); + var container = Task.Run( + async () => + { + try + { + return await _localContentProvider.GetItemByNativePathAsync( + new NativePath(rootDriveInfo.RootDirectory.FullName), + PointInTime.Present); + } + catch + { + return null; + } + } + ).GetAwaiter().GetResult(); + + return (rootDriveInfo, container as IContainer); } private static int GetDriveOrder(DriveType type)