Skip to content

Commit 4dd11b9

Browse files
committed
fix: now it works
1 parent ee86279 commit 4dd11b9

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

Core/Sources/Core/UserDictionary/SystemUserDictionaryHelper.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,25 @@ public enum SystemUserDictionaryHelper: Sendable {
7777
print("dbPath", dbPath)
7878

7979
let url: URL
80+
let needStop: Bool
8081
if !FileManager.default.isReadableFile(atPath: dbPath) {
8182
#if canImport(AppKit)
82-
guard let authorizedURL = Self.promptUserForTextReplacementDirectory() else {
83+
guard let authorizedURL = Self.promptUserForTextReplacementDirectory(), authorizedURL.startAccessingSecurityScopedResource() else {
8384
throw FetchError.fileNotReadable(dbPath)
8485
}
86+
needStop = true
8587
url = authorizedURL
8688
#else
8789
throw FetchError.fileNotReadable(dbPath)
8890
#endif
8991
} else {
92+
needStop = false
9093
url = URL(fileURLWithPath: dbPath)
9194
}
92-
guard url.startAccessingSecurityScopedResource() else {
93-
throw FetchError.fileNotReadable(dbPath)
94-
}
9595
defer {
96-
url.stopAccessingSecurityScopedResource()
96+
if needStop {
97+
url.stopAccessingSecurityScopedResource()
98+
}
9799
}
98100

99101
var db: OpaquePointer?

0 commit comments

Comments
 (0)