SPB Git

Repository Public

PersistenceLocations.swift 1.1 KB 23 lines swift

1import Foundation23public enum PersistenceLocations {4    /// `~/Library/Application Support/NEXTERM/` unless overridden (tests, UI tests).5    public static func applicationSupportDirectory(override: String? = nil) -> URL {6        if let override { return URL(fileURLWithPath: override, isDirectory: true) }7        let base = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first8            ?? FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("Library/Application Support")9        return base.appendingPathComponent("NEXTERM", isDirectory: true)10    }1112    public static func databaseURL(override: String? = nil) -> URL {13        applicationSupportDirectory(override: override).appendingPathComponent("nexterm.sqlite")14    }1516    /// Opens (creating if needed) and migrates the application database.17    public static func openDatabase(override: String? = nil) throws -> SQLiteDatabase {18        let db = try SQLiteDatabase(path: databaseURL(override: override).path)19        try Migrations.migrate(db)20        return db21    }22}23
Files main
Menu

Theme