mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2026-04-01 17:20:09 +02:00
🐛 Use DispatchQueue to manage concurrent access to PATH
This commit is contained in:
@@ -3994,7 +3994,7 @@
|
|||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 1815;
|
CURRENT_PROJECT_VERSION = 1817;
|
||||||
DEAD_CODE_STRIPPING = YES;
|
DEAD_CODE_STRIPPING = YES;
|
||||||
DEBUG = YES;
|
DEBUG = YES;
|
||||||
ENABLE_APP_SANDBOX = NO;
|
ENABLE_APP_SANDBOX = NO;
|
||||||
@@ -4038,7 +4038,7 @@
|
|||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 1815;
|
CURRENT_PROJECT_VERSION = 1817;
|
||||||
DEAD_CODE_STRIPPING = YES;
|
DEAD_CODE_STRIPPING = YES;
|
||||||
DEBUG = NO;
|
DEBUG = NO;
|
||||||
ENABLE_APP_SANDBOX = NO;
|
ENABLE_APP_SANDBOX = NO;
|
||||||
@@ -4220,7 +4220,7 @@
|
|||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 1815;
|
CURRENT_PROJECT_VERSION = 1817;
|
||||||
DEAD_CODE_STRIPPING = YES;
|
DEAD_CODE_STRIPPING = YES;
|
||||||
DEBUG = YES;
|
DEBUG = YES;
|
||||||
ENABLE_APP_SANDBOX = NO;
|
ENABLE_APP_SANDBOX = NO;
|
||||||
@@ -4413,7 +4413,7 @@
|
|||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 1815;
|
CURRENT_PROJECT_VERSION = 1817;
|
||||||
DEAD_CODE_STRIPPING = YES;
|
DEAD_CODE_STRIPPING = YES;
|
||||||
DEBUG = NO;
|
DEBUG = NO;
|
||||||
ENABLE_APP_SANDBOX = NO;
|
ENABLE_APP_SANDBOX = NO;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class RealShell: ShellProtocol {
|
|||||||
|
|
||||||
init(container: Container) {
|
init(container: Container) {
|
||||||
self.container = container
|
self.container = container
|
||||||
self.PATH = RealShell.getPath()
|
self._PATH = RealShell.getPath()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,11 +22,24 @@ class RealShell: ShellProtocol {
|
|||||||
*/
|
*/
|
||||||
private(set) var launchPath: String = "/bin/sh"
|
private(set) var launchPath: String = "/bin/sh"
|
||||||
|
|
||||||
|
/**
|
||||||
|
Thread-safe access to PATH is ensured via this queue.
|
||||||
|
*/
|
||||||
|
private let pathQueue = DispatchQueue(label: "com.nicoverbruggen.phpmon.shell_path")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
For some commands, we need to know what's in the user's PATH.
|
For some commands, we need to know what's in the user's PATH.
|
||||||
The entire PATH is retrieved here, so we can set the PATH in our own terminal as necessary.
|
The entire PATH is retrieved here, so we can set the PATH in our own terminal as necessary.
|
||||||
*/
|
*/
|
||||||
private(set) var PATH: String
|
private var _PATH: String
|
||||||
|
|
||||||
|
/**
|
||||||
|
Accessor for the PATH (thread-safe access with DispatchQueue).
|
||||||
|
*/
|
||||||
|
internal var PATH: String {
|
||||||
|
get { pathQueue.sync { _PATH } }
|
||||||
|
set { pathQueue.sync { _PATH = newValue } }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Exports are additional environment variables set by the user via the custom configuration.
|
Exports are additional environment variables set by the user via the custom configuration.
|
||||||
@@ -45,15 +58,10 @@ class RealShell: ShellProtocol {
|
|||||||
let pipe = Pipe()
|
let pipe = Pipe()
|
||||||
task.standardOutput = pipe
|
task.standardOutput = pipe
|
||||||
task.launch()
|
task.launch()
|
||||||
|
task.waitUntilExit()
|
||||||
|
|
||||||
let path = String(
|
let path = getStringOutput(from: pipe)
|
||||||
data: pipe.fileHandleForReading.readDataToEndOfFile(),
|
return path.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
encoding: String.Encoding.utf8
|
|
||||||
) ?? ""
|
|
||||||
|
|
||||||
try? pipe.fileHandleForReading.close()
|
|
||||||
|
|
||||||
return path
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user