mirror of
https://github.com/metabolist/metatext.git
synced 2024-05-18 08:23:00 +00:00
25 lines
1,005 B
Swift
25 lines
1,005 B
Swift
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
import Foundation
|
|
|
|
extension FileManager {
|
|
func databaseDirectoryURL() throws -> URL {
|
|
let databaseDirectoryURL = try url(for: .applicationSupportDirectory,
|
|
in: .userDomainMask,
|
|
appropriateFor: nil,
|
|
create: true)
|
|
.appendingPathComponent("Database")
|
|
var isDirectory: ObjCBool = false
|
|
|
|
if !fileExists(atPath: databaseDirectoryURL.path, isDirectory: &isDirectory) {
|
|
try createDirectory(at: databaseDirectoryURL,
|
|
withIntermediateDirectories: false,
|
|
attributes: [.protectionKey: FileProtectionType.complete])
|
|
} else if !isDirectory.boolValue {
|
|
throw NSError(domain: NSCocoaErrorDomain, code: NSFileWriteFileExistsError, userInfo: nil)
|
|
}
|
|
|
|
return databaseDirectoryURL
|
|
}
|
|
}
|