@@ -129,18 +129,28 @@ struct APIServer: AsyncParsableCommand {
129129 }
130130
131131 private func initializePluginLoader( log: Logger ) throws -> PluginLoader {
132- // create user-installed plugins directory if it doesn't exist
133- let pluginsURL = PluginLoader . userPluginsDir ( root: Self . appRoot)
134- try FileManager . default. createDirectory ( at: pluginsURL, withIntermediateDirectories: true )
132+ let installRoot = CommandLine . executablePathUrl
133+ . deletingLastPathComponent ( )
134+ . appendingPathComponent ( " .. " )
135+ . standardized
136+ let pluginsURL = PluginLoader . userPluginsDir ( root: installRoot)
137+ var directoryExists : ObjCBool = false
138+ _ = FileManager . default. fileExists ( atPath: pluginsURL. path, isDirectory: & directoryExists)
139+ let userPluginsURL = directoryExists. boolValue ? pluginsURL : nil
135140
136141 // plugins built into the application installed as a macOS app bundle
137142 let appBundlePluginsURL = Bundle . main. resourceURL? . appending ( path: " plugins " )
138143
139144 // plugins built into the application installed as a Unix-like application
140- let installRootPluginsURL = CommandLine . executableDirectoryUrl. appendingPathComponent ( " ../libexec/container/plugins " )
145+ let installRootPluginsURL =
146+ installRoot
147+ . appendingPathComponent ( " libexec " )
148+ . appendingPathComponent ( " container " )
149+ . appendingPathComponent ( " plugins " )
150+ . standardized
141151
142152 let pluginDirectories = [
143- pluginsURL ,
153+ userPluginsURL ,
144154 appBundlePluginsURL,
145155 installRootPluginsURL,
146156 ] . compactMap { $0 }
@@ -150,6 +160,7 @@ struct APIServer: AsyncParsableCommand {
150160 AppBundlePluginFactory ( ) ,
151161 ]
152162
163+ log. info ( " PLUGINS: \( pluginDirectories) " )
153164 let statePath = PluginLoader . defaultPluginResourcePath ( root: Self . appRoot)
154165 try FileManager . default. createDirectory ( at: statePath, withIntermediateDirectories: true )
155166 return PluginLoader ( pluginDirectories: pluginDirectories, pluginFactories: pluginFactories, defaultResourcePath: statePath, log: log)
0 commit comments