From c8d92bd54259e44de70054d4269198bd01c95f83 Mon Sep 17 00:00:00 2001 From: Mohamed Afifi Date: Sun, 15 Oct 2023 09:28:19 -0400 Subject: [PATCH] Extract smaller private methods from ReadingResourcesService (#564) --- .../ReadingService/Sources/ReadingResourcesService.swift | 9 +++++++++ Features/AppDependencies/AppDependencies.swift | 1 - Package.swift | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Domain/ReadingService/Sources/ReadingResourcesService.swift b/Domain/ReadingService/Sources/ReadingResourcesService.swift index 78905154..396c981b 100644 --- a/Domain/ReadingService/Sources/ReadingResourcesService.swift +++ b/Domain/ReadingService/Sources/ReadingResourcesService.swift @@ -94,6 +94,12 @@ public actor ReadingResourcesService { try? fileManager.createDirectory(at: Reading.resourcesDirectory, withIntermediateDirectories: true) + removePreviouslyDownloadedResources() + + copyNewlyDownloadedResource(reading: reading) + } + + private func removePreviouslyDownloadedResources() { do { let downloadedResources = try fileManager.contentsOfDirectory(at: Reading.resourcesDirectory, includingPropertiesForKeys: nil) for resource in downloadedResources { @@ -102,6 +108,9 @@ public actor ReadingResourcesService { } catch { logger.error("Resources failed to list files. Error: \(error)") } + } + + private func copyNewlyDownloadedResource(reading: Reading) { do { let bundleURL = reading.url(inBundle: bundle) try fileManager.copyItem(at: bundleURL, to: reading.directory) diff --git a/Features/AppDependencies/AppDependencies.swift b/Features/AppDependencies/AppDependencies.swift index e9809014..16d1b7ac 100644 --- a/Features/AppDependencies/AppDependencies.swift +++ b/Features/AppDependencies/AppDependencies.swift @@ -25,7 +25,6 @@ public protocol AppDependencies { var supportsCloudKit: Bool { get } - // TODO: Remove async var downloadManager: DownloadManager { get } var analytics: AnalyticsLibrary { get } var readingResources: ReadingResourcesService { get } diff --git a/Package.swift b/Package.swift index 890540f6..dad591dd 100644 --- a/Package.swift +++ b/Package.swift @@ -787,6 +787,7 @@ func dependencyName(of dependency: Target.Dependency) -> String { return "" } +/// Creates an empty test target that links all targets to produce an accurate code coverage. func testTargetLinkingAllPackageTargets(_ targets: [Target]) -> Target { let nonTestTargets = targets.filter { !$0.isTest } return .testTarget(