|
36 | 36 | #include "../../../iocore/eventsystem/P_EventSystem.h" |
37 | 37 |
|
38 | 38 | #include <algorithm> /* std::swap */ |
| 39 | +#include <filesystem> |
39 | 40 |
|
40 | 41 | RemapPluginInst::RemapPluginInst(RemapPluginInfo &plugin) : _plugin(plugin) |
41 | 42 | { |
@@ -102,7 +103,14 @@ PluginFactory::~PluginFactory() |
102 | 103 | _instList.apply([](RemapPluginInst *pluginInst) -> void { delete pluginInst; }); |
103 | 104 | _instList.clear(); |
104 | 105 |
|
105 | | - fs::remove_all(_runtimeDir, _ec); |
| 106 | + { |
| 107 | + uint32_t elevate_access = 0; |
| 108 | + |
| 109 | + REC_ReadConfigInteger(elevate_access, "proxy.config.plugin.load_elevated"); |
| 110 | + ElevateAccess access(elevate_access ? ElevateAccess::FILE_PRIVILEGE : 0); |
| 111 | + |
| 112 | + fs::remove_all(_runtimeDir, _ec); |
| 113 | + } |
106 | 114 |
|
107 | 115 | PluginDbg(_dbg_ctl(), "destroyed plugin factory %s", getUuid()); |
108 | 116 | delete _uuid; |
@@ -226,9 +234,6 @@ PluginFactory::getRemapPlugin(const fs::path &configPath, int argc, char **argv, |
226 | 234 | delete plugin; |
227 | 235 | } |
228 | 236 |
|
229 | | - if (dynamicReloadEnabled && _preventiveCleaning) { |
230 | | - clean(error); |
231 | | - } |
232 | 237 | } else { |
233 | 238 | /* Plugin DSO load failed. */ |
234 | 239 | PluginDbg(_dbg_ctl(), "plugin '%s' DSO load failed", configPath.c_str()); |
@@ -276,6 +281,26 @@ PluginFactory::getEffectivePath(const fs::path &configPath) |
276 | 281 | return path; |
277 | 282 | } |
278 | 283 |
|
| 284 | +void |
| 285 | +PluginFactory::cleanup() |
| 286 | +{ |
| 287 | + std::error_code ec; |
| 288 | + auto path = RecConfigReadRuntimeDir(); |
| 289 | + |
| 290 | + if (path.starts_with("/") && std::filesystem::is_directory(path)) { |
| 291 | + for (const auto &entry : std::filesystem::directory_iterator(path, ec)) { |
| 292 | + if (entry.is_directory()) { |
| 293 | + std::string dir_name = entry.path().string(); |
| 294 | + int dash_count = std::count(dir_name.begin(), dir_name.end(), '-'); // All UUIDs have 4 dashes |
| 295 | + |
| 296 | + if (dash_count == 4) { |
| 297 | + std::filesystem::remove_all(dir_name, ec); |
| 298 | + } |
| 299 | + } |
| 300 | + } |
| 301 | + } |
| 302 | +} |
| 303 | + |
279 | 304 | /** |
280 | 305 | * @brief Find a plugin by path from our linked plugin list by using plugin effective (canonical) path |
281 | 306 | * |
@@ -326,9 +351,3 @@ PluginFactory::indicatePostReload(bool reloadSuccessful) |
326 | 351 |
|
327 | 352 | PluginDso::loadedPlugins()->indicatePostReload(reloadSuccessful, pluginUsed, getUuid()); |
328 | 353 | } |
329 | | - |
330 | | -void |
331 | | -PluginFactory::clean(std::string & /* error ATS_UNUSED */) |
332 | | -{ |
333 | | - fs::remove_all(_runtimeDir, _ec); |
334 | | -} |
|
0 commit comments