Skip to content

Commit

Permalink
devonfw#799: clean code improvements (devonfw#884)
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille authored Dec 10, 2024
1 parent 95e7d15 commit 7866298
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
39 changes: 21 additions & 18 deletions cli/src/main/java/com/devonfw/tools/ide/io/FileAccessImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -608,32 +608,35 @@ 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<PosixFilePermission>) 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) {
throw new IllegalStateException("Failed to extract " + file + " to " + targetDir, e);
}
}

@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<PosixFilePermission>) 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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> {
};

/**
Expand Down

0 comments on commit 7866298

Please sign in to comment.