diff options
author | Andrej Mihajlov <and@mullvad.net> | 2020-12-02 12:27:39 +0100 |
---|---|---|
committer | Andrej Mihajlov <and@mullvad.net> | 2020-12-03 13:32:24 +0100 |
commit | ec574085703ea1c8b2d4538596961beb910c4382 (patch) | |
tree | 73cf8bbdb74fe5575606664bccd0232ffa911803 /Sources/Shared/FileManager+Extension.swift | |
parent | WireGuardKit: Assert that resolutionResults must not contain failures (diff) | |
download | wireguard-apple-ec574085703ea1c8b2d4538596961beb910c4382.tar.xz wireguard-apple-ec574085703ea1c8b2d4538596961beb910c4382.zip |
Move all source files to `Sources/` and rename WireGuardKit targets
Signed-off-by: Andrej Mihajlov <and@mullvad.net>
Diffstat (limited to 'Sources/Shared/FileManager+Extension.swift')
-rw-r--r-- | Sources/Shared/FileManager+Extension.swift | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Sources/Shared/FileManager+Extension.swift b/Sources/Shared/FileManager+Extension.swift new file mode 100644 index 0000000..d52ec0b --- /dev/null +++ b/Sources/Shared/FileManager+Extension.swift @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: MIT +// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved. + +import Foundation +import os.log + +extension FileManager { + static var appGroupId: String? { + #if os(iOS) + let appGroupIdInfoDictionaryKey = "com.wireguard.ios.app_group_id" + #elseif os(macOS) + let appGroupIdInfoDictionaryKey = "com.wireguard.macos.app_group_id" + #else + #error("Unimplemented") + #endif + return Bundle.main.object(forInfoDictionaryKey: appGroupIdInfoDictionaryKey) as? String + } + private static var sharedFolderURL: URL? { + guard let appGroupId = FileManager.appGroupId else { + os_log("Cannot obtain app group ID from bundle", log: OSLog.default, type: .error) + return nil + } + guard let sharedFolderURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupId) else { + wg_log(.error, message: "Cannot obtain shared folder URL") + return nil + } + return sharedFolderURL + } + + static var logFileURL: URL? { + return sharedFolderURL?.appendingPathComponent("tunnel-log.bin") + } + + static var networkExtensionLastErrorFileURL: URL? { + return sharedFolderURL?.appendingPathComponent("last-error.txt") + } + + static func deleteFile(at url: URL) -> Bool { + do { + try FileManager.default.removeItem(at: url) + } catch { + return false + } + return true + } +} |