diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-10-01 15:05:43 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2022-10-01 15:05:43 -0500 |
| commit | 36b1e1d4537d817d7a02987a25e5f0cc792d5f8f (patch) | |
| tree | 36f8446732e995388b3c9f322044f220e8d81ca8 /src | |
| parent | 664a3e988a0f0beb2f5a75602ea468d339ac87a6 (diff) | |
| download | slskd-36b1e1d4537d817d7a02987a25e5f0cc792d5f8f.tar.gz | |
respect force scan option, gracefully handle init failures
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Application.cs | 11 | ||||
| -rw-r--r-- | src/slskd/Shares/ShareService.cs | 12 |
2 files changed, 16 insertions, 7 deletions
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; } } |
