diff --git a/LightlessSync/FileCache/FileCacheManager.cs b/LightlessSync/FileCache/FileCacheManager.cs index 34e5a5b..17f22de 100644 --- a/LightlessSync/FileCache/FileCacheManager.cs +++ b/LightlessSync/FileCache/FileCacheManager.cs @@ -189,7 +189,14 @@ public sealed class FileCacheManager : IHostedService Parallel.ForEach(allEntities, entity => { - cacheDict[entity.PrefixedFilePath] = entity; + if (entity != null && entity.PrefixedFilePath != null) + { + cacheDict[entity.PrefixedFilePath] = entity; + } + else + { + _logger.LogWarning("Null FileCacheEntity or PrefixedFilePath encountered in cache population: {entity}", entity); + } }); var cleanedPaths = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); @@ -253,6 +260,7 @@ public sealed class FileCacheManager : IHostedService { if (_fileCaches.TryGetValue(hash, out var caches)) { + _logger.LogTrace("Removing from DB: {hash} => {path}", hash, prefixedFilePath); var removedCount = caches?.RemoveAll(c => string.Equals(c.PrefixedFilePath, prefixedFilePath, StringComparison.Ordinal)); _logger.LogTrace("Removed from DB: {count} file(s) with hash {hash} and file cache {path}", removedCount, hash, prefixedFilePath); @@ -397,6 +405,12 @@ public sealed class FileCacheManager : IHostedService private FileCacheEntity? Validate(FileCacheEntity fileCache) { + if (string.IsNullOrWhiteSpace(fileCache.ResolvedFilepath)) + { + _logger.LogWarning("FileCacheEntity has empty ResolvedFilepath for hash {hash}, prefixed path {prefixed}", fileCache.Hash, fileCache.PrefixedFilePath); + RemoveHashedFile(fileCache.Hash, fileCache.PrefixedFilePath); + return null; + } var file = new FileInfo(fileCache.ResolvedFilepath); if (!file.Exists) {