mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
Remove deprecated connectivity check (#6278)
This commit is contained in:
@@ -58,11 +58,6 @@ internal extension Configuration.FileGraph.FilePath {
|
||||
if let mockedValue = Configuration.FileGraph.FilePath.mockedNetworkResults[urlString] {
|
||||
configString = mockedValue
|
||||
} else {
|
||||
// Handle missing network
|
||||
guard Reachability.connectivityStatus != .disconnected else {
|
||||
return try handleMissingNetwork(urlString: urlString, cachedFilePath: cachedFilePath)
|
||||
}
|
||||
|
||||
// Handle wrong url format
|
||||
guard let url = URL(string: urlString) else {
|
||||
throw Issue.genericWarning("Invalid configuration entry: \"\(urlString)\" isn't a valid url.")
|
||||
@@ -117,21 +112,6 @@ internal extension Configuration.FileGraph.FilePath {
|
||||
return filePath
|
||||
}
|
||||
|
||||
private mutating func handleMissingNetwork(urlString: String, cachedFilePath: String?) throws -> String {
|
||||
if let cachedFilePath {
|
||||
queuedPrintError(
|
||||
"warning: No internet connectivity: Unable to load remote config from \"\(urlString)\". "
|
||||
+ "Using cached version as a fallback."
|
||||
)
|
||||
self = .existing(path: cachedFilePath)
|
||||
return cachedFilePath
|
||||
}
|
||||
throw Issue.genericWarning(
|
||||
"No internet connectivity: Unable to load remote config from \"\(urlString)\". "
|
||||
+ "Also didn't found cached version to fallback to."
|
||||
)
|
||||
}
|
||||
|
||||
private mutating func handleWrongData(
|
||||
urlString: String,
|
||||
cachedFilePath: String?,
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
#if !os(Linux)
|
||||
import SystemConfiguration
|
||||
#endif
|
||||
|
||||
/// Helper enum providing the static var `connectivityStatus`
|
||||
enum Reachability {
|
||||
enum ConnectivityStatus {
|
||||
case connected, disconnected, unknown
|
||||
}
|
||||
|
||||
/// Returns whether the device is connected to a network, if known.
|
||||
/// On Linux, this always evaluates to `nil`.
|
||||
static var connectivityStatus: ConnectivityStatus {
|
||||
#if os(Linux)
|
||||
return .unknown
|
||||
#else
|
||||
var zeroAddress = sockaddr_in()
|
||||
zeroAddress.sin_len = UInt8(MemoryLayout<sockaddr_in>.size)
|
||||
zeroAddress.sin_family = sa_family_t(AF_INET)
|
||||
|
||||
guard let defaultRouteReachability = withUnsafePointer(to: &zeroAddress, {
|
||||
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
|
||||
SCNetworkReachabilityCreateWithAddress(nil, $0)
|
||||
}
|
||||
}) else {
|
||||
return .unknown
|
||||
}
|
||||
|
||||
var flags: SCNetworkReachabilityFlags = []
|
||||
if !SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags) {
|
||||
return .unknown
|
||||
}
|
||||
|
||||
if flags.isEmpty {
|
||||
return .disconnected
|
||||
}
|
||||
|
||||
let isReachable = flags.contains(.reachable)
|
||||
let needsConnection = flags.contains(.connectionRequired)
|
||||
|
||||
return (isReachable && !needsConnection) ? .connected : .disconnected
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user