diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 8f6370ae..81560ffb 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -3994,7 +3994,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1815; + CURRENT_PROJECT_VERSION = 1817; DEAD_CODE_STRIPPING = YES; DEBUG = YES; ENABLE_APP_SANDBOX = NO; @@ -4038,7 +4038,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1815; + CURRENT_PROJECT_VERSION = 1817; DEAD_CODE_STRIPPING = YES; DEBUG = NO; ENABLE_APP_SANDBOX = NO; @@ -4220,7 +4220,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1815; + CURRENT_PROJECT_VERSION = 1817; DEAD_CODE_STRIPPING = YES; DEBUG = YES; ENABLE_APP_SANDBOX = NO; @@ -4413,7 +4413,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1815; + CURRENT_PROJECT_VERSION = 1817; DEAD_CODE_STRIPPING = YES; DEBUG = NO; ENABLE_APP_SANDBOX = NO; diff --git a/phpmon/Common/PHP/PhpConfigurationFile.swift b/phpmon/Common/PHP/PhpConfigurationFile.swift index 5b3e22c2..4b8bb7ff 100644 --- a/phpmon/Common/PHP/PhpConfigurationFile.swift +++ b/phpmon/Common/PHP/PhpConfigurationFile.swift @@ -135,7 +135,7 @@ class PhpConfigurationFile: CreatedFromFile { public func reload() { let newLines = try! String(contentsOfFile: self.filePath) .components(separatedBy: "\n") - + // Update all properties atomically lines = newLines extensions = PhpExtension.from(container, newLines, filePath: self.filePath) diff --git a/phpmon/Common/Shell/RealShell.swift b/phpmon/Common/Shell/RealShell.swift index 9887fa7c..4965808d 100644 --- a/phpmon/Common/Shell/RealShell.swift +++ b/phpmon/Common/Shell/RealShell.swift @@ -13,7 +13,7 @@ class RealShell: ShellProtocol { init(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" + /** + 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. 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. @@ -45,15 +58,10 @@ class RealShell: ShellProtocol { let pipe = Pipe() task.standardOutput = pipe task.launch() + task.waitUntilExit() - let path = String( - data: pipe.fileHandleForReading.readDataToEndOfFile(), - encoding: String.Encoding.utf8 - ) ?? "" - - try? pipe.fileHandleForReading.close() - - return path + let path = getStringOutput(from: pipe) + return path.trimmingCharacters(in: .whitespacesAndNewlines) } /**