From 280fdc07f2ee87939d112cb83b652c3fa8c156eb Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Fri, 26 Mar 2021 13:43:54 -0500 Subject: [PATCH] Fixed a bug where if a chapter had multiple archive files, they wouldn't all be extracted due to short circuit in ExtractArchive. Now I add the file id then flatten afterwards. (#113) --- API/Services/CacheService.cs | 13 ++++++++++--- build.sh | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/API/Services/CacheService.cs b/API/Services/CacheService.cs index 1a847fdf1..d998a4976 100644 --- a/API/Services/CacheService.cs +++ b/API/Services/CacheService.cs @@ -41,12 +41,19 @@ namespace API.Services public async Task Ensure(int chapterId) { EnsureCacheDirectory(); - Chapter chapter = await _unitOfWork.VolumeRepository.GetChapterAsync(chapterId); + var chapter = await _unitOfWork.VolumeRepository.GetChapterAsync(chapterId); + var fileCount = 0; + var extractPath = GetCachePath(chapterId); foreach (var file in chapter.Files) { - var extractPath = GetCachePath(chapterId); - _archiveService.ExtractArchive(file.FilePath, extractPath); + _archiveService.ExtractArchive(file.FilePath, Path.Join(extractPath, file.Id + "")); + fileCount++; + } + + if (fileCount > 1) + { + new DirectoryInfo(extractPath).Flatten(); } return chapter; diff --git a/build.sh b/build.sh index 9119b76f4..a8d59b9d1 100644 --- a/build.sh +++ b/build.sh @@ -62,7 +62,7 @@ Package() ProgressStart "Creating $runtime Package for $framework" - + # TODO: Use no-restore? Because Build should have already done it for us echo "Building" cd API echo dotnet publish -c release --self-contained --runtime $runtime -o "$lOutputFolder" --framework $framework