diff --git a/scm-webapp/src/main/java/sonia/scm/plugin/PendingPluginInstallation.java b/scm-webapp/src/main/java/sonia/scm/plugin/PendingPluginInstallation.java index 1da4823b7d..13f18c74c3 100644 --- a/scm-webapp/src/main/java/sonia/scm/plugin/PendingPluginInstallation.java +++ b/scm-webapp/src/main/java/sonia/scm/plugin/PendingPluginInstallation.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - + package sonia.scm.plugin; import org.slf4j.Logger; @@ -50,10 +50,14 @@ class PendingPluginInstallation { void cancel() { String name = plugin.getDescriptor().getInformation().getName(); LOG.info("cancel installation of plugin {}", name); - try { - Files.delete(file); - } catch (IOException ex) { - throw new PluginFailedToCancelInstallationException("failed to cancel plugin installation ", name, ex); + if (Files.exists(file)) { + try { + Files.delete(file); + } catch (IOException ex) { + throw new PluginFailedToCancelInstallationException("failed to cancel plugin installation ", name, ex); + } + } else { + LOG.info("plugin file {} did not exists for plugin {}; nothing deleted", file, name); } } } diff --git a/scm-webapp/src/test/java/sonia/scm/plugin/PendingPluginInstallationTest.java b/scm-webapp/src/test/java/sonia/scm/plugin/PendingPluginInstallationTest.java index b668870488..f8fe44e8f0 100644 --- a/scm-webapp/src/test/java/sonia/scm/plugin/PendingPluginInstallationTest.java +++ b/scm-webapp/src/test/java/sonia/scm/plugin/PendingPluginInstallationTest.java @@ -59,8 +59,13 @@ class PendingPluginInstallationTest { } @Test - void shouldThrowExceptionIfCancelFailed(@TempDir Path directory) { + void shouldThrowExceptionIfCancelFailed(@TempDir Path directory) throws IOException { Path file = directory.resolve("file"); + Files.createDirectory(file); + + Path makeFileNotDeletable = file.resolve("not_deletable"); + Files.write(makeFileNotDeletable, "42".getBytes()); + when(plugin.getDescriptor().getInformation().getName()).thenReturn("scm-awesome-plugin"); PendingPluginInstallation installation = new PendingPluginInstallation(plugin, file);