Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ class CrowdinLocalizationDownloader: CrowdinDownloaderProtocol {
xcstrings: filesToDownload.filter({ $0.isXcstrings }),
with: hash, timestamp: timestamp, for: localization)
} else {
self.completion?(self.strings, self.plurals, self.errors)
// No files to download; safely read accumulated state
self.lock.lock()
let strings = self.strings
let plurals = self.plurals
let errors = self.errors
self.lock.unlock()
Comment on lines +48 to +52
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lock is not released if an exception occurs between lock() and unlock(). Consider using defer to ensure the lock is always unlocked, even in exceptional cases: self.lock.lock(); defer { self.lock.unlock() }

Copilot uses AI. Check for mistakes.
self.completion?(strings, plurals, errors)
}
} else if let error = error {
self.lock.lock()
Expand Down
7 changes: 6 additions & 1 deletion Sources/Tests/Core/RealLocalizationProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ class RealLocalizationProviderTests: XCTestCase {
]

override func setUp() {

// Ensure global state from other tests doesn't affect these tests
Bundle.unswizzle()
Localization.current = nil
CrowdinSDK.currentLocalization = nil
ManifestManager.clear()
}

override func tearDown() {
Expand Down Expand Up @@ -69,6 +73,7 @@ class RealLocalizationProviderTests: XCTestCase {
func testFetchDataAfterRemoteStoragePrepared(with localization: String) {
let localStorage = LocalLocalizationStorage(localization: localization)
let remoteStorage = CrowdinRemoteLocalizationStorage(localization: localization, config: crowdinProviderConfig)
remoteStorage.manifestManager.clear()
localizationProvider = LocalizationProvider(localization: localization, localStorage: localStorage, remoteStorage: remoteStorage)
let expectation = expectation(description: "Localization refreshed")

Expand Down
Loading