Skip to content

Commit fb0e802

Browse files
Vladislav AlekseevAvito iOSBot
authored andcommitted
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

Lines changed: 9 additions & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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 {
Lines changed: 34 additions & 0 deletions
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

Lines changed: 7 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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 {

0 commit comments

Comments
 (0)