From 36b1e1d4537d817d7a02987a25e5f0cc792d5f8f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 1 Oct 2022 15:05:43 -0500 Subject: respect force scan option, gracefully handle init failures --- src/slskd/Application.cs | 11 ++++++++--- src/slskd/Shares/ShareService.cs | 12 ++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 2a52f2f5..57f968ec 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -371,11 +371,16 @@ namespace slskd _ = CheckVersionAsync(); } - // initialize shares. most of the time shares will be loaded from disk, but - // if this is the first run or the user deleted cached files, a full scan will be performed if (!OptionsAtStartup.Flags.NoShareScan) { - await Shares.InitializeAsync(forceRescan: OptionsAtStartup.Flags.ForceShareScan); + try + { + await Shares.InitializeAsync(forceRescan: OptionsAtStartup.Flags.ForceShareScan); + } + catch (Exception) + { + Log.Error("Failed to initialize shares. Sharing is disabled"); + } } if (OptionsAtStartup.Flags.NoConnect) diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index 86b19f3d..cebb15f6 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -252,8 +252,12 @@ namespace slskd.Shares { try { - // see if we need to 'restore' the database from disk, and do so - if (CacheStorageMode == StorageMode.Memory || (CacheStorageMode == StorageMode.Disk && !ShareRepository.TryValidateDatabase(Program.ConnectionStrings.Shares))) + if (forceRescan) + { + Log.Warning("Performing a forced re-scan of shares"); + await ScanAsync(); + } + else if (CacheStorageMode == StorageMode.Memory || (CacheStorageMode == StorageMode.Disk && !ShareRepository.TryValidateDatabase(Program.ConnectionStrings.Shares))) { Log.Debug($"Share cache {(CacheStorageMode == StorageMode.Memory ? "StorageMode is 'Memory'" : "database is missing from disk")}. Attempting to load from backup..."); @@ -261,7 +265,7 @@ namespace slskd.Shares if (!ShareRepository.TryValidateDatabase(Program.ConnectionStrings.SharesBackup)) { Log.Warning("Share cache couldn't be loaded from backup"); - Log.Warning("Performing a full share scan to rebuild the cache"); + await InitializeAsync(forceRescan: true); } Log.Debug("Share cache backup located. Attempting to restore..."); @@ -298,7 +302,7 @@ namespace slskd.Shares } else { - Log.Error("Failed to initialize shares, and an attempt to force a full scan to repair failed. Check your filesystem."); + Log.Error("Failed to initialize shares, and an attempt to force a full scan to repair failed"); throw; } } -- cgit v1.2.3