Skip to content

Commit fb0e802

Browse files
Vladislav AlekseevAvito iOSBot
Vladislav Alekseev
authored and
Avito iOSBot
committed
MBS-13416: support linux common paths
GitOrigin-RevId: 3783d82a49e82771e203cab7dabbbccab9129596
1 parent 782eac3 commit fb0e802

17 files changed

+72
-28
lines changed

Sources/FileSystem/DI/FileSystemModuleDependencies.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,17 @@ public final class FileSystemModuleDependencies: ModuleDependencies {
103103
)
104104
}
105105
di.register(type: CommonlyUsedPathsProvider.self) { di in
106-
try DefaultCommonlyUsedPathsProvider(
106+
#if os(macOS)
107+
try AppleCommonlyUsedPathsProvider(
107108
fileManager: di.resolve()
108109
)
110+
#elseif os(Linux)
111+
try LinuxCommonlyUsedPathsProvider(
112+
fileManager: di.resolve()
113+
)
114+
#else
115+
#error("Unsupported OS")
116+
#endif
109117
}
110118
}
111119
}

Sources/FileSystem/Files/CommonlyUsedPathsProvider/DefaultCommonlyUsedPathsProvider.swift renamed to Sources/FileSystem/Files/CommonlyUsedPathsProvider/AppleCommonlyUsedPathsProvider.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
#if os(macOS)
12
import Foundation
23
import PathLib
34

4-
public final class DefaultCommonlyUsedPathsProvider: CommonlyUsedPathsProvider {
5+
public final class AppleCommonlyUsedPathsProvider: CommonlyUsedPathsProvider {
56
private let fileManager: FileManager
67

78
public init(fileManager: FileManager) {
@@ -60,3 +61,4 @@ extension SearchDomain {
6061
}
6162
}
6263
}
64+
#endif

Sources/FileSystem/Files/CommonlyUsedPathsProvider/CommonlyUsedPathsProvider.swift

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public enum SearchDomain {
55
/// User's home directory --- place to install user's personal items (`~`)
66
case user
77

8+
#if os(macOS)
89
/// Local to the current machine --- place to install items available to everyone on this machine (`/Library`)
910
case local
1011

@@ -13,6 +14,7 @@ public enum SearchDomain {
1314

1415
/// Provided by Apple, unmodifiable (/System)
1516
case system
17+
#endif
1618
}
1719

1820
public protocol CommonlyUsedPathsProvider {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import Foundation
2+
import PathLib
3+
4+
public final class LinuxCommonlyUsedPathsProvider: CommonlyUsedPathsProvider {
5+
private let fileManager: FileManager
6+
7+
public init(fileManager: FileManager) {
8+
self.fileManager = fileManager
9+
}
10+
11+
public struct UnsupportedCommonPath: Error, CustomStringConvertible {
12+
public let locationName: String
13+
14+
public var description: String {
15+
"Location \(locationName) is not supported on Linux"
16+
}
17+
}
18+
19+
public func applications(inDomain domain: SearchDomain, create: Bool) throws -> AbsolutePath {
20+
throw UnsupportedCommonPath(locationName: "Applications")
21+
}
22+
23+
public func caches(inDomain domain: SearchDomain, create: Bool) throws -> AbsolutePath {
24+
return AbsolutePath(NSTemporaryDirectory())
25+
}
26+
27+
public func library(inDomain domain: SearchDomain, create: Bool) throws -> AbsolutePath {
28+
throw UnsupportedCommonPath(locationName: "Library")
29+
}
30+
31+
public var currentWorkingDirectory: AbsolutePath {
32+
AbsolutePath(fileManager.currentDirectoryPath)
33+
}
34+
}

Sources/FileSystem/Files/FileSystem/CommonlyUsedPathsProviderFactory/CommonlyUsedPathsProviderFactoryImpl.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ public final class CommonlyUsedPathsProviderFactoryImpl: CommonlyUsedPathsProvid
88
}
99

1010
public var commonlyUsedPathsProvider: CommonlyUsedPathsProvider {
11-
return DefaultCommonlyUsedPathsProvider(fileManager: fileManager)
11+
#if os(macOS)
12+
return AppleCommonlyUsedPathsProvider(fileManager: fileManager)
13+
#elseif os(Linux)
14+
return LinuxCommonlyUsedPathsProvider(fileManager: fileManager)
15+
#else
16+
#error("Unsupported OS")
17+
#endif
1218
}
1319
}

Sources/Graphite/GraphiteMetricHandlerImpl.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public final class GraphiteMetricHandlerImpl: GraphiteMetricHandler {
1717

1818
let streamReopener = StreamReopener(maximumAttemptsToReopenStream: 10)
1919

20-
#if os(macOS) || os(iOS) || os(tvOS)
20+
#if os(macOS)
2121
outputStream = AppleEasyOutputStream(
2222
outputStreamProvider: AppleNetworkSocketOutputStreamProvider(
2323
host: graphiteSocketAddress.host,

Sources/IO/AppleEasyOutputStream.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import AtomicModels
22
import Foundation
33

4-
#if os(macOS) || os(iOS) || os(tvOS)
4+
#if os(macOS)
55

66
// swiftlint:disable async
77
public final class AppleEasyOutputStream: NSObject, EasyOutputStream, StreamDelegate {

Sources/IO/AppleNetworkSocketOutputStreamProvider.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
#if os(macOS) || os(iOS) || os(tvOS)
3+
#if os(macOS)
44
public final class AppleNetworkSocketOutputStreamProvider: OutputStreamProvider {
55
private let host: String
66
private let port: Int

Sources/LaunchdUtils/LaunchdSocketActivation.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public enum LaunchdSocketActivation {
66
/// - Throws:`LaunchdSocketActivationError`
77
/// - Returns: a set of file descriptors corresponding to a socket service that launchd(8) has created and advertised on behalf of the job
88
public static func activateSocket(name: String) throws -> [Int32] {
9-
#if os(macOS) || os(iOS) || os(tvOS)
9+
#if os(macOS)
1010
var ld_sockets = UnsafeMutablePointer<Int32>.allocate(capacity: 0)
1111
defer {
1212
ld_sockets.deallocate()

Sources/ProcessController/Process+ProcessGroup.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public extension Process {
1515
* This method uses private API and will throw an error if it won't be able to use the private API.
1616
*/
1717
func setStartsNewProcessGroup(_ value: Bool) throws {
18-
#if os(macOS) || os(iOS) || os(tvOS)
18+
#if os(macOS)
1919
if let concreteTaskClass = NSClassFromString("NSConcreteTask"), self.isKind(of: concreteTaskClass) {
2020
self.perform(Selector(("setStartsNewProcessGroup:")), with: value)
2121
} else {

Sources/Statsd/AppleStatsdClient.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if os(macOS) || os(iOS) || os(tvOS)
1+
#if os(macOS)
22
import Foundation
33
import Network
44
import SocketModels

Tests/FileSystemTests/DefaultCommonlyUsedPathsProviderTests.swift renamed to Tests/FileSystemTests/AppleCommonlyUsedPathsProviderTests.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
#if os(macOS)
12
import FileSystem
23
import PathLib
34
import TestHelpers
45
import XCTest
56

6-
final class DefaultCommonlyUsedPathsProviderTests: XCTestCase {
7-
private lazy var defaultCommonlyUsedPathsProvider = DefaultCommonlyUsedPathsProvider(fileManager: fileManager)
8-
private let fileManager = FileManager()
7+
final class AppleCommonlyUsedPathsProviderTests: XCTestCase {
8+
private lazy var fileManager = FileManager()
9+
private lazy var defaultCommonlyUsedPathsProvider = AppleCommonlyUsedPathsProvider(
10+
fileManager: fileManager
11+
)
912

1013
func test___applications() {
1114
XCTAssertEqual(
@@ -28,3 +31,4 @@ final class DefaultCommonlyUsedPathsProviderTests: XCTestCase {
2831
)
2932
}
3033
}
34+
#endif

Tests/FileSystemTests/CommonlyUsedPathsProviderFactoryImplTests.swift

-12
This file was deleted.

Tests/GraphiteClientTests/GraphiteClientTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import IO
44
import XCTest
55

66
final class GraphiteClientTests: XCTestCase {
7-
#if os(macOS) || os(iOS) || os(tvOS)
7+
#if os(macOS)
88
func disabled___test___simple_use_case() throws {
99
let stream = AppleEasyOutputStream(
1010
outputStreamProvider: AppleNetworkSocketOutputStreamProvider(host: "host", port: 65432),

Tests/IOTests/AppleEasyOutputStreamTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import IO
22
import TestHelpers
33
import XCTest
44

5-
#if os(macOS) || os(iOS) || os(tvOS)
5+
#if os(macOS)
66
final class AppleEasyOutputStreamTests: XCTestCase {
77
let inMemoryOutputStreamProvider = FakeInMemoryOutputStreamProvider()
88

Tests/IOTests/BoundStreamsOutputStreamProvider.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22
import IO
33

4-
#if os(macOS) || os(iOS) || os(tvOS)
4+
#if os(macOS)
55
final class BoundStreamsOutputStreamProvider: OutputStreamProvider {
66

77
let inputStream: InputStream

Tests/TestHelpers/TestFailing.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public func failTest(
77
line: UInt = #line
88
) -> Never {
99
XCTFail(message, file: file, line: line)
10-
#if os(macOS) || os(iOS) || os(tvOS)
10+
#if os(macOS)
1111
NSException(name: NSExceptionName(rawValue: message), reason: nil, userInfo: nil).raise()
1212
#endif
1313
fatalError("Failing test with message: \(message)")

0 commit comments

Comments
 (0)