Fixed a bug in CleanupBookmarks where the Except was deleting all files because the path separators didn't match. (#932)

This commit is contained in:
Joseph Milazzo 2022-01-13 08:15:23 -08:00 committed by GitHub
parent 920f187cd4
commit 7eaa0248c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 81 additions and 6 deletions

View file

@ -174,16 +174,17 @@ namespace API.Services.Tasks
/// </summary>
public async Task CleanupBookmarks()
{
// Search all files in bookmarks/
// except bookmark files and delete those
// Search all files in bookmarks/ except bookmark files and delete those
var bookmarkDirectory =
(await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.BookmarkDirectory)).Value;
var allBookmarkFiles = _directoryService.GetFiles(bookmarkDirectory, searchOption: SearchOption.AllDirectories);
var allBookmarkFiles = _directoryService.GetFiles(bookmarkDirectory, searchOption: SearchOption.AllDirectories).Select(f => _directoryService.FileSystem.Path.GetFullPath(f));
var bookmarks = (await _unitOfWork.UserRepository.GetAllBookmarksAsync())
.Select(b => _directoryService.FileSystem.Path.Join(bookmarkDirectory,
b.FileName));
.Select(b => _directoryService.FileSystem.Path.GetFullPath(_directoryService.FileSystem.Path.Join(bookmarkDirectory,
b.FileName)));
var filesToDelete = allBookmarkFiles.Except(bookmarks);
var filesToDelete = allBookmarkFiles.ToList().Except(bookmarks).ToList();
_logger.LogDebug("[Bookmarks] Bookmark cleanup wants to delete {Count} files", filesToDelete.Count());
_directoryService.DeleteFiles(filesToDelete);