[java-identity-provider] 01/03: IDP-2297 Explore extending the Plugin and Module Infrastructure to allow Jetty installation
Rod Widdowson
rdw at steadingsoftware.com
Sat Aug 3 14:22:40 UTC 2024
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=55b9ac5fd3785ad424acf5eaf2d4f3e36ab8d084
commit 55b9ac5fd3785ad424acf5eaf2d4f3e36ab8d084
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Jul 23 16:54:37 2024 +0100
IDP-2297 Explore extending the Plugin and Module Infrastructure to allow Jetty installation
https://shibboleth.atlassian.net/browse/IDP-2297
Add directory move to the operations that can be rolled back.
---
.../plugin/impl/RollbackPluginInstall.java | 43 ++++++++++++++++------
.../idp/installer/plugin/impl/RollbackTester.java | 32 ++++++++++++++--
2 files changed, 60 insertions(+), 15 deletions(-)
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/RollbackPluginInstall.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/RollbackPluginInstall.java
index 780d39ec5..6ce0c3114 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/RollbackPluginInstall.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/RollbackPluginInstall.java
@@ -16,6 +16,7 @@ package net.shibboleth.idp.installer.plugin.impl;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
+import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
@@ -31,6 +32,7 @@ import javax.annotation.Nonnull;
import org.slf4j.Logger;
+import net.shibboleth.idp.installer.InstallerSupport;
import net.shibboleth.idp.module.IdPModule;
import net.shibboleth.idp.plugin.IdPPlugin;
import net.shibboleth.profile.module.Module.ModuleResource;
@@ -174,17 +176,36 @@ public class RollbackPluginInstall implements AutoCloseable {
}
for (int i = filesRenamedAway.size()-1; i >=0; i--) {
final Pair<Path, Path> filePair = filesRenamedAway.get(i);
- final Path from = filePair.getFirst();
- final Path to = filePair.getSecond();
- assert from != null && to != null;
- try (final InputStream in = new BufferedInputStream(
- new FileInputStream(to.toFile()));
- final OutputStream out = new BufferedOutputStream(
- new FileOutputStream(from.toFile()))) {
- log.trace("Copying {} to {}", filePair.getSecond());
- in.transferTo(out);
- } catch (final Throwable t) {
- log.error("Could not copy {} to {}, continuing ", filePair.getSecond(), filePair.getFirst(), t);
+ //
+ // "from" and "to" in the following are the what was done. So what we need to undo
+ //
+ final Path fromPath = filePair.getFirst();
+ final Path toPath = filePair.getSecond();
+ assert fromPath != null && toPath != null;
+ final File from = fromPath.toFile();
+ final File to = toPath.toFile();
+
+ if (to.isDirectory()) {
+ if (from.exists()) {
+ //
+ // Something else been put there. remove it
+ //
+ InstallerSupport.deleteTree(fromPath);
+ }
+ try {
+ log.trace("Moving {} to {}", toPath, fromPath);
+ Files.move(toPath, fromPath);
+ } catch (final Throwable t) {
+ log.error("Could not move {} to {}, continuing.", toPath, fromPath, t);
+ }
+ } else {
+ try (final InputStream in = new BufferedInputStream(new FileInputStream(to));
+ final OutputStream out = new BufferedOutputStream(new FileOutputStream(from))) {
+ log.trace("Copying {} to {}", toPath, fromPath);
+ in.transferTo(out);
+ } catch (final Throwable t) {
+ log.error("Could not copy {} to {}, continuing.", toPath, fromPath, t);
+ }
}
}
return true;
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/RollbackTester.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/RollbackTester.java
index cd788cd84..6054c478f 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/RollbackTester.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/RollbackTester.java
@@ -59,7 +59,15 @@ public class RollbackTester {
final Path to = Files.createTempFile(parent, "renamed", "file");
final Path mc = Files.createTempDirectory(parent, "mod");
final Path from = parent.resolve("fromFile");
- final Pair<Path, Path> renamed = new Pair<>(from, to);
+
+ // simulate a rename followed by a create
+ final Path fromDir =Files.createTempDirectory(parent, "fromDir");
+ final Path toDir =Files.createTempDirectory(parent, "toDir");
+ final Path toDirChild = Files.createTempFile(toDir, "toDir", "child");
+ final Path fromDirChild = fromDir.resolve(toDir.relativize(toDirChild));
+
+ final Pair<Path, Path> renamedFiles = new Pair<>(from, to);
+ final Pair<Path, Path> renamedDirs = new Pair<>(fromDir, toDir);
final IdPModule enabled1 = new TestModule("enabled1", null, null);
final IdPModule enabled2 = new TestModule("enabled2", null, new ModuleException());
final IdPModule disabled1 = new TestModule("disabled1", null, null);
@@ -74,6 +82,11 @@ public class RollbackTester {
assertTrue(to.toFile().exists());
assertTrue(copied.toFile().exists());
+ assertTrue(fromDir.toFile().exists());
+ assertFalse(fromDirChild.toFile().exists());
+ assertTrue(toDir.toFile().exists());
+ assertTrue(toDirChild.toFile().exists());
+
enabled1.enable(ctx);
assertTrue(enabled1.isEnabled(ctx));
@@ -85,7 +98,8 @@ public class RollbackTester {
try (final RollbackPluginInstall rp = new RollbackPluginInstall(new ModuleContext(parentString), new HashMap<>())) {
rp.getFilesCopied().add(copied);
- rp.getFilesRenamedAway().add(renamed);
+ rp.getFilesRenamedAway().add(renamedFiles);
+ rp.getFilesRenamedAway().add(renamedDirs);
rp.getModulesDisabled().add(disabled1);
rp.getModulesDisabled().add(disabled2);
rp.getModulesEnabled().add(enabled1);
@@ -102,7 +116,12 @@ public class RollbackTester {
assertFalse(disabled2.isEnabled(ctx));
assertFalse(from.toFile().exists());
assertTrue(to.toFile().exists());
- assertTrue(copied.toFile().exists());
+ assertTrue(copied.toFile().exists());
+ assertTrue(fromDir.toFile().exists());
+ assertFalse(fromDirChild.toFile().exists());
+ assertTrue(toDir.toFile().exists());
+ assertTrue(toDirChild.toFile().exists());
+
} else {
assertFalse(enabled1.isEnabled(ctx));
assertTrue(enabled2.isEnabled(ctx)); // threw instead
@@ -112,7 +131,12 @@ public class RollbackTester {
assertTrue(from.toFile().exists()); //copied to
assertTrue(to.toFile().exists()); // copied from
- assertFalse(copied.toFile().exists()); //deleted
+ assertTrue(fromDir.toFile().exists()); // renamed to
+ assertTrue(fromDirChild.toFile().exists());
+ assertFalse(toDir.toFile().exists());
+ assertFalse(toDirChild.toFile().exists());
+
+ assertFalse(copied.toFile().exists()); //deleted
}
} finally {
deleteIt(copied);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list