diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-08-03 09:25:10 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-08-03 09:25:10 -0500 |
| commit | 43f3bf2d128dc7e44043a8ef2199d75cdb0d3d4b (patch) | |
| tree | 8a5f8c25b7e63b4a684d04500a0f6e4d188d32c3 /src/slskd/Application/Shares/SharedFileCache.cs | |
| parent | 71815c51cb305ba97a7732be52509eb64fcd4aa3 (diff) | |
| download | slskd-43f3bf2d128dc7e44043a8ef2199d75cdb0d3d4b.tar.gz | |
add plumbing to rescan shares via API
Diffstat (limited to 'src/slskd/Application/Shares/SharedFileCache.cs')
| -rw-r--r-- | src/slskd/Application/Shares/SharedFileCache.cs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/slskd/Application/Shares/SharedFileCache.cs b/src/slskd/Application/Shares/SharedFileCache.cs index a06e86f6..439e5eb8 100644 --- a/src/slskd/Application/Shares/SharedFileCache.cs +++ b/src/slskd/Application/Shares/SharedFileCache.cs @@ -109,21 +109,21 @@ namespace slskd.Shares /// <returns>The operation context.</returns> public async Task FillAsync() { - if (!StateMonitor.CurrentValue.Ready) + if (SyncRoot.TryEnterWriteLock(0)) { - Log.Warning("Cache fill rejected; cache is already filling."); - return; + Log.Warning("Shared file scan rejected; scan is already in progress."); + throw new ShareScanInProgressException("Shared files are already being scanned."); } await Task.Yield(); - var sw = new Stopwatch(); - sw.Start(); - SyncRoot.EnterWriteLock(); try { + var sw = new Stopwatch(); + sw.Start(); + StateMonitor.SetValue(state => state with { Ready = false, FillProgress = 0 }); CreateTable(); @@ -150,7 +150,7 @@ namespace slskd.Shares { if (files.ContainsKey(file.Key)) { - Console.WriteLine($"[WARNING] File {file.Key} shared in directory {directory} has already been cached. This is probably a misconfiguration of the shared directories."); + Log.Warning($"File {file.Key} shared in directory {directory} has already been cached. This is probably a misconfiguration of the shared directories (is a subdirectory being re-shared?)."); } files[file.Key] = file.Value; @@ -170,13 +170,13 @@ namespace slskd.Shares Files = files; StateMonitor.SetValue(state => state with { Ready = true, FillProgress = 1, Directories = directories.Count, Files = files.Count }); + + Log.Information($"Shared file cache recreated in {sw.ElapsedMilliseconds}ms. Directories: {directories.Count}, Files: {files.Count}"); } finally { SyncRoot.ExitWriteLock(); } - - sw.Stop(); } /// <summary> |
