diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-10-01 14:58:04 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2022-10-01 14:58:04 -0500 |
| commit | efb613beb826bd27b8296c75d61993bdbdcc0bb5 (patch) | |
| tree | e841253521a82a50b009b6819c1990bb4543dc47 /src/slskd/Shares | |
| parent | 09ba5e716c3431cf4db1a8eea954ca420f3f05d7 (diff) | |
| download | slskd-efb613beb826bd27b8296c75d61993bdbdcc0bb5.tar.gz | |
move init to ShareService
Diffstat (limited to 'src/slskd/Shares')
| -rw-r--r-- | src/slskd/Shares/IShareService.cs | 7 | ||||
| -rw-r--r-- | src/slskd/Shares/ShareService.cs | 30 |
2 files changed, 24 insertions, 13 deletions
diff --git a/src/slskd/Shares/IShareService.cs b/src/slskd/Shares/IShareService.cs index 429ab529..2a18f5b3 100644 --- a/src/slskd/Shares/IShareService.cs +++ b/src/slskd/Shares/IShareService.cs @@ -90,9 +90,10 @@ namespace slskd.Shares bool TryCancelScan(); /// <summary> - /// Attempt to load shares from disk. + /// Initializes the service and shares. /// </summary> - /// <returns>A value indicating whether shares were loaded.</returns> - bool TryLoadFromDisk(); + /// <param name="forceRescan">A value indicating whether a full re-scan of shares should be performed.</param> + /// <returns>The operation context.</returns> + Task InitializeAsync(bool forceRescan = false); } }
\ No newline at end of file diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index ff40481e..86b19f3d 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -244,10 +244,11 @@ namespace slskd.Shares } /// <summary> - /// Attempt to load shares from disk. + /// Initializes the service and shares. /// </summary> - /// <returns>A value indicating whether shares were loaded.</returns> - public bool TryLoadFromDisk() + /// <param name="forceRescan">A value indicating whether a full re-scan of shares should be performed.</param> + /// <returns>The operation context.</returns> + public async Task InitializeAsync(bool forceRescan = false) { try { @@ -259,21 +260,22 @@ namespace slskd.Shares // the backup is missing; we can't do anything but recreate it from scratch if (!ShareRepository.TryValidateDatabase(Program.ConnectionStrings.SharesBackup)) { - Log.Debug("Share cache backup is missing; unable to restore"); - return false; + Log.Warning("Share cache couldn't be loaded from backup"); + Log.Warning("Performing a full share scan to rebuild the cache"); } Log.Debug("Share cache backup located. Attempting to restore..."); Repository.RestoreFrom(connectionString: Program.ConnectionStrings.SharesBackup); - Log.Debug("Share cache successfully restored from backup"); + Log.Information("Share cache successfully restored from backup"); } // one of several thigns happened above before we got here: // the storage mode is memory, and we loaded the in-memory db from a valid backup // the storage mode is disk, and the file is there and valid // the storage mode is disk but either missing or invalid, and we restored from a valid backup + // we failed to load the cache from disk or backup, and performed a full scan successfully // at this point there is a valid (existing, schema matching expected schema) database at the primary connection string State.SetValue(state => state with { @@ -284,13 +286,21 @@ namespace slskd.Shares Directories = Repository.CountDirectories(), Files = Repository.CountFiles(), }); - - return true; } catch (Exception ex) { - Log.Debug(ex, "Error loading shared file cache: {Message}", ex.Message); - return false; + Log.Warning(ex, "Error initializing shares: {Message}", ex.Message); + + if (!forceRescan) + { + Log.Warning("Re-attempting initializtion"); + await InitializeAsync(forceRescan: true); + } + else + { + Log.Error("Failed to initialize shares, and an attempt to force a full scan to repair failed. Check your filesystem."); + throw; + } } } |
