From 0b0858752510306ccf4bd8b3d082a0af511bc654 Mon Sep 17 00:00:00 2001 From: mbilda Date: Fri, 28 Feb 2025 13:31:30 +0100 Subject: [PATCH 1/4] https://github.com/devonfw/IDEasy/issues/910 : Cannot update Intellij on Linux: FileAlreadyExistsException - Added LinkOption.NOFOLLOW_LINKS to verify if the symlink file itself exists or not - and not the target file/folder --- .../java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java index cbf161436..8c22ba743 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/LocalToolCommandlet.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.nio.file.Files; +import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.Collection; @@ -88,7 +89,7 @@ public boolean install(boolean silent, EnvironmentContext environmentContext) { // we need to link the version or update the link. Path toolPath = getToolPath(); FileAccess fileAccess = this.context.getFileAccess(); - if (Files.exists(toolPath)) { + if (Files.exists(toolPath, LinkOption.NOFOLLOW_LINKS)) { fileAccess.backup(toolPath); } fileAccess.mkdirs(toolPath.getParent()); From 3a9de8ffc7502cc5cd193eeebf5326761d0b479e Mon Sep 17 00:00:00 2001 From: mbilda Date: Fri, 28 Feb 2025 14:49:12 +0100 Subject: [PATCH 2/4] https://github.com/devonfw/IDEasy/issues/910 : Cannot update Intellij on Linux: FileAlreadyExistsException - Added LinkOption.NOFOLLOW_LINKS to verify if the symlink file itself exists or not - and not the target file/folder --- cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java b/cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java index 16214d248..f106a59e3 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java @@ -781,7 +781,7 @@ public void extractPkg(Path file, Path targetDir) { @Override public void delete(Path path) { - if (!Files.exists(path)) { + if (!Files.exists(path, LinkOption.NOFOLLOW_LINKS)) { this.context.trace("Deleting {} skipped as the path does not exist.", path); return; } From f85614d76b3a42f5813e360311b35011b3b537cb Mon Sep 17 00:00:00 2001 From: mbilda Date: Tue, 4 Mar 2025 11:10:02 +0100 Subject: [PATCH 3/4] https://github.com/devonfw/IDEasy/issues/910 : Cannot update Intellij on Linux: FileAlreadyExistsException - Removed exists() function from fileAccess because its just calling "super" - Adjusted usages of fileAccess.exists() --- .../tools/ide/commandlet/UpgradeSettingsCommandlet.java | 6 +++--- cli/src/main/java/com/devonfw/tools/ide/io/FileAccess.java | 6 ------ .../main/java/com/devonfw/tools/ide/io/FileAccessImpl.java | 5 ----- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/UpgradeSettingsCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/UpgradeSettingsCommandlet.java index 1a5b366bb..930dedc1b 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/UpgradeSettingsCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/UpgradeSettingsCommandlet.java @@ -1,5 +1,6 @@ package com.devonfw.tools.ide.commandlet; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.function.Function; @@ -59,7 +60,7 @@ private void updateLegacyFolder(Path folder, String legacyName, String newName) Path newFolder = folder.resolve(newName); if (fileAccess.isExpectedFolder(legacyFolder)) { try { - if (!fileAccess.exists(newFolder)) { + if (!Files.exists(newFolder)) { fileAccess.move(legacyFolder, newFolder, StandardCopyOption.REPLACE_EXISTING); this.context.success("Successfully renamed folder '{}' to '{}' in {}.", legacyName, newName, folder); } @@ -106,9 +107,8 @@ private void updateProperties() { } environmentVariables = environmentVariables.getParent(); } - FileAccess fileAccess = this.context.getFileAccess(); Path templatePropertiesDir = this.context.getSettingsTemplatePath().resolve(IdeContext.FOLDER_CONF); - if (fileAccess.exists(templatePropertiesDir)) { + if (Files.exists(templatePropertiesDir)) { EnvironmentVariablesPropertiesFile environmentVariablesProperties = new EnvironmentVariablesPropertiesFile(null, EnvironmentVariablesType.CONF, templatePropertiesDir, null, this.context); updateProperties(environmentVariablesProperties); diff --git a/cli/src/main/java/com/devonfw/tools/ide/io/FileAccess.java b/cli/src/main/java/com/devonfw/tools/ide/io/FileAccess.java index 94b8c305b..8e0d4d4fc 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/io/FileAccess.java +++ b/cli/src/main/java/com/devonfw/tools/ide/io/FileAccess.java @@ -44,12 +44,6 @@ public interface FileAccess { */ boolean isFile(Path file); - /** - * @param file the {@link Path} to check. - * @return {@code true} if the given {@code file} points to an existing file, {@code false} otherwise (the given {@link Path} does not exist - */ - boolean exists(Path file); - /** * @param folder the {@link Path} to check. * @return {@code true} if the given {@code folder} points to an existing directory, {@code false} otherwise (a warning is logged in this case). diff --git a/cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java b/cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java index f106a59e3..dae5669db 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java @@ -220,11 +220,6 @@ public boolean isFile(Path file) { return true; } - @Override - public boolean exists(Path file) { - return Files.exists(file); - } - @Override public boolean isExpectedFolder(Path folder) { From 9c073f49530dde20ea47e29f5e03367baeb7c2f3 Mon Sep 17 00:00:00 2001 From: mbilda Date: Wed, 5 Mar 2025 07:10:47 +0100 Subject: [PATCH 4/4] https://github.com/devonfw/IDEasy/issues/910 : Cannot update Intellij on Linux: FileAlreadyExistsException - Added entry to CHANGELOG.adoc --- CHANGELOG.adoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index c5668e51f..a4a323f88 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -6,6 +6,7 @@ This file documents all notable changes to https://github.com/devonfw/IDEasy[IDE Release with new features and bugfixes: +* https://github.com/devonfw/IDEasy/issues/910[#910]: Cannot update Intellij on Linux - FileAlreadyExistsException * https://github.com/devonfw/IDEasy/issues/38[#38]: Implement ToolCommandlet for Python The full list of changes for this release can be found in https://github.com/devonfw/IDEasy/milestone/23?closed=1[milestone 2025.03.001].