@@ -67,22 +67,15 @@ ensure(FileJustChanged0) ->
67
67
{error , {enabled_plugins_mismatch , FileJustChanged , OurFile }}
68
68
end .
69
69
70
+ % % @doc Prepares the file system and installs all enabled plugins.
70
71
setup () ->
71
- case application :get_env (rabbit , plugins_expand_dir ) of
72
- {ok , ExpandDir } ->
73
- case filelib :is_dir (ExpandDir ) of
74
- true ->
75
- rabbit_log :info (
76
- " \" ~s \" is no longer used to expand plugins.~n "
77
- " RabbitMQ still manages this directory "
78
- " but will stop doing so in the future." , [ExpandDir ]),
79
-
80
- _ = delete_recursively (ExpandDir );
81
- false ->
82
- ok
83
- end ;
84
- undefined ->
85
- ok
72
+ {ok , ExpandDir } = application :get_env (rabbit , plugins_expand_dir ),
73
+
74
+ % % Eliminate the contents of the destination directory
75
+ case delete_recursively (ExpandDir ) of
76
+ ok -> ok ;
77
+ {error , E1 } -> throw ({error , {cannot_delete_plugins_expand_dir ,
78
+ [ExpandDir , E1 ]}})
86
79
end ,
87
80
88
81
{ok , EnabledFile } = application :get_env (rabbit , enabled_plugins_file ),
@@ -135,61 +128,10 @@ extract_schema(#plugin{type = dir, location = Location}, SchemaDir) ->
135
128
136
129
% % @doc Lists the plugins which are currently running.
137
130
active () ->
138
- LoadedPluginNames = maybe_keep_required_deps (false , loaded_plugin_names ()),
131
+ {ok , ExpandDir } = application :get_env (rabbit , plugins_expand_dir ),
132
+ InstalledPlugins = plugin_names (list (ExpandDir )),
139
133
[App || {App , _ , _ } <- rabbit_misc :which_applications (),
140
- lists :member (App , LoadedPluginNames )].
141
-
142
- loaded_plugin_names () ->
143
- {ok , PluginsPath } = application :get_env (rabbit , plugins_dir ),
144
- PluginsDirs = split_path (PluginsPath ),
145
- lists :flatmap (
146
- fun (PluginsDir ) ->
147
- PluginsDirComponents = filename :split (PluginsDir ),
148
- loaded_plugin_names (code :get_path (), PluginsDirComponents , [])
149
- end ,
150
- PluginsDirs ).
151
-
152
- loaded_plugin_names ([Path | OtherPaths ], PluginsDirComponents , PluginNames ) ->
153
- case lists :sublist (filename :split (Path ), length (PluginsDirComponents )) of
154
- PluginsDirComponents ->
155
- case build_plugin_name_from_code_path (Path ) of
156
- undefined ->
157
- loaded_plugin_names (
158
- OtherPaths , PluginsDirComponents , PluginNames );
159
- PluginName ->
160
- loaded_plugin_names (
161
- OtherPaths , PluginsDirComponents ,
162
- [list_to_atom (PluginName ) | PluginNames ])
163
- end ;
164
- _ ->
165
- loaded_plugin_names (OtherPaths , PluginsDirComponents , PluginNames )
166
- end ;
167
- loaded_plugin_names ([], _ , PluginNames ) ->
168
- PluginNames .
169
-
170
- build_plugin_name_from_code_path (Path ) ->
171
- AppPath = case filelib :is_dir (Path ) of
172
- true ->
173
- case filelib :wildcard (filename :join (Path , " *.app" )) of
174
- [AP | _ ] -> AP ;
175
- [] -> undefined
176
- end ;
177
- false ->
178
- EZ = filename :dirname (filename :dirname (Path )),
179
- case filelib :is_regular (EZ ) of
180
- true ->
181
- case find_app_path_in_ez (EZ ) of
182
- {ok , AP } -> AP ;
183
- _ -> undefined
184
- end ;
185
- _ ->
186
- undefined
187
- end
188
- end ,
189
- case AppPath of
190
- undefined -> undefined ;
191
- _ -> filename :basename (AppPath , " .app" )
192
- end .
134
+ lists :member (App , InstalledPlugins )].
193
135
194
136
% % @doc Get the list of plugins which are ready to be enabled.
195
137
list (PluginsPath ) ->
@@ -279,19 +221,25 @@ running_plugins() ->
279
221
% %----------------------------------------------------------------------------
280
222
281
223
prepare_plugins (Enabled ) ->
282
- AllPlugins = installed_plugins (),
224
+ {ok , PluginsDistDir } = application :get_env (rabbit , plugins_dir ),
225
+ {ok , ExpandDir } = application :get_env (rabbit , plugins_expand_dir ),
226
+
227
+ AllPlugins = list (PluginsDistDir ),
283
228
Wanted = dependencies (false , Enabled , AllPlugins ),
284
229
WantedPlugins = lookup_plugins (Wanted , AllPlugins ),
285
230
{ValidPlugins , Problems } = validate_plugins (WantedPlugins ),
286
231
maybe_warn_about_invalid_plugins (Problems ),
232
+ case filelib :ensure_dir (ExpandDir ++ " /" ) of
233
+ ok -> ok ;
234
+ {error , E2 } -> throw ({error , {cannot_create_plugins_expand_dir ,
235
+ [ExpandDir , E2 ]}})
236
+ end ,
237
+ [prepare_plugin (Plugin , ExpandDir ) || Plugin <- ValidPlugins ],
287
238
288
- [prepare_dir_plugin (ValidPlugin ) || ValidPlugin <- ValidPlugins ],
239
+ [prepare_dir_plugin (PluginAppDescPath ) ||
240
+ PluginAppDescPath <- filelib :wildcard (ExpandDir ++ " /*/ebin/*.app" )],
289
241
Wanted .
290
242
291
- installed_plugins () ->
292
- {ok , PluginsDistDir } = application :get_env (rabbit , plugins_dir ),
293
- list (PluginsDistDir ).
294
-
295
243
maybe_warn_about_invalid_plugins ([]) ->
296
244
ok ;
297
245
maybe_warn_about_invalid_plugins (InvalidPlugins ) ->
@@ -404,60 +352,40 @@ is_version_supported(Version, ExpectedVersions) ->
404
352
end .
405
353
406
354
clean_plugins (Plugins ) ->
407
- [clean_plugin (Plugin ) || Plugin <- Plugins ].
355
+ {ok , ExpandDir } = application :get_env (rabbit , plugins_expand_dir ),
356
+ [clean_plugin (Plugin , ExpandDir ) || Plugin <- Plugins ].
408
357
409
- clean_plugin (Plugin ) ->
358
+ clean_plugin (Plugin , ExpandDir ) ->
410
359
{ok , Mods } = application :get_key (Plugin , modules ),
411
- PluginEbinDir = code :lib_dir (Plugin , ebin ),
412
-
413
360
application :unload (Plugin ),
414
361
[begin
415
362
code :soft_purge (Mod ),
416
363
code :delete (Mod ),
417
364
false = code :is_loaded (Mod )
418
365
end || Mod <- Mods ],
419
-
420
- code :del_path (PluginEbinDir ).
421
-
422
- plugin_ebin_dir (# plugin {type = ez , location = Location }) ->
423
- case find_app_path_in_ez (Location ) of
424
- {ok , AppPath } ->
425
- filename :join (Location , filename :dirname (AppPath ));
426
- {error , Reason } ->
427
- {error , Reason }
428
- end ;
429
- plugin_ebin_dir (# plugin {type = dir , location = Location }) ->
430
- filename :join (Location , " ebin" ).
431
-
432
- prepare_dir_plugin (# plugin {name = Name } = Plugin ) ->
433
- PluginEbinDir = case plugin_ebin_dir (Plugin ) of
434
- {error , Reason } ->
435
- throw ({plugin_ebin_dir_not_found , Name , Reason });
436
- Dir ->
437
- Dir
438
- end ,
439
- case code :add_patha (PluginEbinDir ) of
440
- true ->
441
- case filelib :wildcard (PluginEbinDir ++ " /*.beam" ) of
442
- [] ->
366
+ delete_recursively (rabbit_misc :format (" ~s /~s " , [ExpandDir , Plugin ])).
367
+
368
+ prepare_dir_plugin (PluginAppDescPath ) ->
369
+ PluginEbinDir = filename :dirname (PluginAppDescPath ),
370
+ Plugin = filename :basename (PluginAppDescPath , " .app" ),
371
+ code :add_patha (PluginEbinDir ),
372
+ case filelib :wildcard (PluginEbinDir ++ " /*.beam" ) of
373
+ [] ->
374
+ ok ;
375
+ [BeamPath | _ ] ->
376
+ Module = list_to_atom (filename :basename (BeamPath , " .beam" )),
377
+ case code :ensure_loaded (Module ) of
378
+ {module , _ } ->
443
379
ok ;
444
- [BeamPath | _ ] ->
445
- Module = list_to_atom (filename :basename (BeamPath , " .beam" )),
446
- case code :ensure_loaded (Module ) of
447
- {module , _ } ->
448
- ok ;
449
- {error , badfile } ->
450
- rabbit_log :error (" Failed to enable plugin \" ~s \" : "
451
- " it may have been built with an "
452
- " incompatible (more recent?) "
453
- " version of Erlang~n " , [Name ]),
454
- throw ({plugin_built_with_incompatible_erlang , Name });
455
- Error ->
456
- throw ({plugin_module_unloadable , Name , Error })
457
- end
458
- end ;
459
- {error , bad_directory } ->
460
- throw ({plugin_ebin_path_incorrect , Name , PluginEbinDir })
380
+ {error , badfile } ->
381
+ rabbit_log :error (" Failed to enable plugin \" ~s \" : "
382
+ " it may have been built with an "
383
+ " incompatible (more recent?) "
384
+ " version of Erlang~n " , [Plugin ]),
385
+ throw ({plugin_built_with_incompatible_erlang , Plugin });
386
+ Error ->
387
+ throw ({plugin_module_unloadable , Plugin , Error })
388
+ end
461
389
end .
462
390
463
391
% %----------------------------------------------------------------------------
@@ -468,6 +396,12 @@ delete_recursively(Fn) ->
468
396
{error , {Path , E }} -> {error , {cannot_delete , Path , E }}
469
397
end .
470
398
399
+ prepare_plugin (# plugin {type = ez , location = Location }, ExpandDir ) ->
400
+ zip :unzip (Location , [{cwd , ExpandDir }]);
401
+ prepare_plugin (# plugin {type = dir , name = Name , location = Location },
402
+ ExpandDir ) ->
403
+ rabbit_file :recursive_copy (Location , filename :join ([ExpandDir , Name ])).
404
+
471
405
plugin_info ({ez , EZ }) ->
472
406
case read_app_file (EZ ) of
473
407
{application , Name , Props } -> mkplugin (Name , Props , ez , EZ );
@@ -494,29 +428,21 @@ mkplugin(Name, Props, Type, Location) ->
494
428
broker_version_requirements = BrokerVersions ,
495
429
dependency_version_requirements = DepsVersions }.
496
430
497
- find_app_path_in_ez (EZ ) ->
431
+ read_app_file (EZ ) ->
498
432
case zip :list_dir (EZ ) of
499
433
{ok , [_ |ZippedFiles ]} ->
500
434
case find_app_files (ZippedFiles ) of
501
435
[AppPath |_ ] ->
502
- {ok , AppPath };
436
+ {ok , [{AppPath , AppFile }]} =
437
+ zip :extract (EZ , [{file_list , [AppPath ]}, memory ]),
438
+ parse_binary (AppFile );
503
439
[] ->
504
440
{error , no_app_file }
505
441
end ;
506
442
{error , Reason } ->
507
443
{error , {invalid_ez , Reason }}
508
444
end .
509
445
510
- read_app_file (EZ ) ->
511
- case find_app_path_in_ez (EZ ) of
512
- {ok , AppPath } ->
513
- {ok , [{AppPath , AppFile }]} =
514
- zip :extract (EZ , [{file_list , [AppPath ]}, memory ]),
515
- parse_binary (AppFile );
516
- {error , Reason } ->
517
- {error , Reason }
518
- end .
519
-
520
446
find_app_files (ZippedFiles ) ->
521
447
{ok , RE } = re :compile (" ^.*/ebin/.*.app$" ),
522
448
[Path || {zip_file , Path , _ , _ , _ , _ } <- ZippedFiles ,
0 commit comments