From 7866298fb2d3250486eb772dcab11d2055156817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hohwiller?= Date: Tue, 10 Dec 2024 13:14:55 +0100 Subject: [PATCH] #799: clean code improvements (#884) --- .../devonfw/tools/ide/io/FileAccessImpl.java | 39 ++++++++++--------- .../tools/ide/io/PathCopyListener.java | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-) 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 763616e2a..87a3896f3 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 @@ -608,25 +608,9 @@ public void extractZip(Path file, Path targetDir) { for (Path root : fs.getRootDirectories()) { size += getFileSizeRecursive(root); } - try (IdeProgressBar bp = this.context.newProgressbarForExtracting(size)) { - PathCopyListener listener = (source, target, directory) -> { - if (directory) { - return; - } - if (!context.getSystemInfo().isWindows()) { - try { - Object attribute = Files.getAttribute(source, "zip:permissions"); - if (attribute instanceof Set permissionSet) { - Files.setPosixFilePermissions(target, (Set) permissionSet); - } - } catch (Exception e) { - context.error(e, "Failed to transfer zip permissions for {}", target); - } - } - bp.stepBy(getFileSize(target)); - }; + try (final IdeProgressBar progressBar = this.context.newProgressbarForExtracting(size)) { for (Path root : fs.getRootDirectories()) { - copy(root, targetDir, FileCopyMode.EXTRACT, listener); + copy(root, targetDir, FileCopyMode.EXTRACT, (s, t, d) -> onFileCopiedFromZip(s, t, d, progressBar)); } } } catch (IOException e) { @@ -634,6 +618,25 @@ public void extractZip(Path file, Path targetDir) { } } + @SuppressWarnings("unchecked") + private void onFileCopiedFromZip(Path source, Path target, boolean directory, IdeProgressBar progressBar) { + + if (directory) { + return; + } + if (!context.getSystemInfo().isWindows()) { + try { + Object attribute = Files.getAttribute(source, "zip:permissions"); + if (attribute instanceof Set permissionSet) { + Files.setPosixFilePermissions(target, (Set) permissionSet); + } + } catch (Exception e) { + context.error(e, "Failed to transfer zip permissions for {}", target); + } + } + progressBar.stepBy(getFileSize(target)); + } + @Override public void extractTar(Path file, Path targetDir, TarCompression compression) { diff --git a/cli/src/main/java/com/devonfw/tools/ide/io/PathCopyListener.java b/cli/src/main/java/com/devonfw/tools/ide/io/PathCopyListener.java index 442e3abe9..62b389e77 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/io/PathCopyListener.java +++ b/cli/src/main/java/com/devonfw/tools/ide/io/PathCopyListener.java @@ -13,7 +13,7 @@ public interface PathCopyListener { /** * An empty {@link PathCopyListener} instance doing nothing. */ - static PathCopyListener NONE = (s, t, d) -> { + PathCopyListener NONE = (s, t, d) -> { }; /**