Skip to content

Commit

Permalink
Extract smaller private methods from ReadingResourcesService (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamede1945 authored Oct 15, 2023
1 parent 0648ffe commit c8d92bd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Domain/ReadingService/Sources/ReadingResourcesService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion Features/AppDependencies/AppDependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c8d92bd

Please sign in to comment.