Delete plugins marked for uninstall

This commit is contained in:
Rene Pfeuffer
2019-09-16 14:27:56 +02:00
parent 38f05fe689
commit 7ec2b0c31d
3 changed files with 29 additions and 3 deletions

View File

@@ -45,6 +45,8 @@ import java.nio.file.Path;
public final class InstalledPlugin implements Plugin
{
public static final String UNINSTALL_MARKER_FILENAME = "uninstall";
/**
* Constructs a new plugin wrapper.
* @param descriptor wrapped plugin

View File

@@ -29,6 +29,7 @@ import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -78,12 +79,37 @@ public final class PluginBootstrap {
LOG.info("core plugin extraction is disabled");
}
uninstallMarkedPlugins(pluginDirectory.toPath());
return PluginsInternal.collectPlugins(classLoaderLifeCycle, pluginDirectory.toPath());
} catch (IOException ex) {
throw new PluginLoadException("could not load plugins", ex);
}
}
private void uninstallMarkedPlugins(Path pluginDirectory) {
try {
java.nio.file.Files.list(pluginDirectory)
.filter(java.nio.file.Files::isDirectory)
.filter(this::isMarkedForUninstall)
.forEach(this::uninstall);
} catch (IOException e) {
LOG.warn("error occurred while checking for plugins that should be uninstalled", e);
}
}
private boolean isMarkedForUninstall(Path path) {
return java.nio.file.Files.exists(path.resolve(InstalledPlugin.UNINSTALL_MARKER_FILENAME));
}
private void uninstall(Path path) {
try {
LOG.info("deleting plugin directory {}", path);
IOUtil.delete(path.toFile());
} catch (IOException e) {
LOG.warn("could not delete plugin directory {}", path, e);
}
}
private void renameOldPluginsFolder(File pluginDirectory) {
if (new File(pluginDirectory, "classpath.xml").exists()) {
File backupDirectory = new File(pluginDirectory.getParentFile(), "plugins.v1");
@@ -96,7 +122,6 @@ public final class PluginBootstrap {
}
}
private boolean isCorePluginExtractionDisabled() {
return Boolean.getBoolean("sonia.scm.boot.disable-core-plugin-extraction");
}

View File

@@ -39,7 +39,6 @@ import com.google.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.NotFoundException;
import sonia.scm.ScmConstraintViolationException;
import sonia.scm.event.ScmEventBus;
import sonia.scm.lifecycle.RestartEvent;
import sonia.scm.version.Version;
@@ -193,7 +192,7 @@ public class DefaultPluginManager implements PluginManager {
dependencyTracker.removeInstalled(installed.getDescriptor());
try {
Files.createFile(installed.getDirectory().resolve("uninstall"));
Files.createFile(installed.getDirectory().resolve(InstalledPlugin.UNINSTALL_MARKER_FILENAME));
} catch (IOException e) {
throw new PluginException("could not mark plugin " + name + " in path " + installed.getDirectory() + " for uninstall", e);
}