Skip to content

Commit

Permalink
#799: fix zip extraction to preserve file attributes (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille authored Dec 9, 2024
1 parent 45a25d5 commit afcaffc
Show file tree
Hide file tree
Showing 18 changed files with 368 additions and 238 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Release with new features and bugfixes:
* https://github.com/devonfw/IDEasy/issues/782[#782]: Fix IDE_ROOT variable on Linux
* https://github.com/devonfw/IDEasy/issues/637[#637]: Added option to disable updates
* https://github.com/devonfw/IDEasy/issues/764[#764]: IDEasy not working properly in CMD
* https://github.com/devonfw/IDEasy/issues/799[#799]: binaries from zip download lack executable flags
* https://github.com/devonfw/IDEasy/issues/81[#81]: Implement Toolcommandlet for Kubernetes
* https://github.com/devonfw/IDEasy/issues/737[#737]: Adds cd command to ide shell
* https://github.com/devonfw/IDEasy/issues/758[#758]: Create status commandlet
Expand Down
49 changes: 43 additions & 6 deletions cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,50 @@ default Path getSettingsTemplatePath() {
ProcessContext newProcess();

/**
* Prepares the {@link IdeProgressBar} initializes task name and maximum size as well as the behaviour and style.
*
* @param taskName name of the task.
* @param size of the content.
* @return {@link IdeProgressBar} to use.
* @param title the {@link IdeProgressBar#getTitle() title}.
* @param size the {@link IdeProgressBar#getMaxSize() expected maximum size}.
* @param unitName the {@link IdeProgressBar#getUnitName() unit name}.
* @param unitSize the {@link IdeProgressBar#getUnitSize() unit size}.
* @return the new {@link IdeProgressBar} to use.
*/
IdeProgressBar newProgressBar(String title, long size, String unitName, long unitSize);

/**
* @param title the {@link IdeProgressBar#getTitle() title}.
* @param size the {@link IdeProgressBar#getMaxSize() expected maximum size} in bytes.
* @return the new {@link IdeProgressBar} to use.
*/
IdeProgressBar prepareProgressBar(String taskName, long size);
default IdeProgressBar newProgressBarInMib(String title, long size) {

return newProgressBar(title, size, "MiB", 1048576);
}

/**
* @param size the {@link IdeProgressBar#getMaxSize() expected maximum size} in bytes.
* @return the new {@link IdeProgressBar} for copy.
*/
default IdeProgressBar newProgressBarForDownload(long size) {

return newProgressBarInMib(IdeProgressBar.TITLE_DOWNLOADING, size);
}

/**
* @param size the {@link IdeProgressBar#getMaxSize() expected maximum size} in bytes.
* @return the new {@link IdeProgressBar} for extracting.
*/
default IdeProgressBar newProgressbarForExtracting(long size) {

return newProgressBarInMib(IdeProgressBar.TITLE_EXTRACTING, size);
}

/**
* @param size the {@link IdeProgressBar#getMaxSize() expected maximum size} in bytes.
* @return the new {@link IdeProgressBar} for copy.
*/
default IdeProgressBar newProgressbarForCopying(long size) {

return newProgressBarInMib(IdeProgressBar.TITLE_COPYING, size);
}

/**
* @return the {@link DirectoryMerger} used to configure and merge the workspace for an {@link com.devonfw.tools.ide.tool.ide.IdeToolCommandlet IDE}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ protected String readLine() {
}

@Override
public IdeProgressBar prepareProgressBar(String taskName, long size) {
return new IdeProgressBarConsole(getSystemInfo(), taskName, size);
public IdeProgressBar newProgressBar(String title, long size, String unitName, long unitSize) {

return new IdeProgressBarConsole(getSystemInfo(), title, size, unitName, unitSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,59 @@
*/
public abstract class AbstractIdeProgressBar implements IdeProgressBar {

private long currentProgress;
/** @see #getTitle() */
protected final String title;

/** @see #getMaxSize() */
protected final long maxSize;

/** @see #getUnitName() */
protected final String unitName;

private final long maxLength;
/** @see #getUnitSize() */
protected final long unitSize;

private long currentProgress;

/**
* @param maxLength the maximum length of the progress bar.
* The constructor.
*
* @param title the {@link #getTitle() title}.
* @param maxSize the {@link #getMaxSize() maximum size}.
* @param unitName the {@link #getUnitName() unit name}.
* @param unitSize the {@link #getUnitSize() unit size}.
*/
public AbstractIdeProgressBar(long maxLength) {
public AbstractIdeProgressBar(String title, long maxSize, String unitName, long unitSize) {

super();
this.title = title;
this.maxSize = maxSize;
this.unitName = unitName;
this.unitSize = unitSize;
}

@Override
public String getTitle() {

return this.title;
}

@Override
public long getMaxSize() {

return this.maxSize;
}

@Override
public String getUnitName() {

this.maxLength = maxLength;
return this.unitName;
}

@Override
public long getMaxLength() {
public long getUnitSize() {

return maxLength;
return this.unitSize;
}

/**
Expand All @@ -38,8 +75,8 @@ public long getMaxLength() {
*/
protected void stepTo(long stepPosition) {

if ((this.maxLength > 0) && (stepPosition > this.maxLength)) {
stepPosition = this.maxLength; // clip to max avoiding overflow
if ((this.maxSize > 0) && (stepPosition > this.maxSize)) {
stepPosition = this.maxSize; // clip to max avoiding overflow
}
this.currentProgress = stepPosition;
doStepTo(stepPosition);
Expand All @@ -56,11 +93,11 @@ protected void stepTo(long stepPosition) {
public void stepBy(long stepSize) {

this.currentProgress += stepSize;
if (this.maxLength > 0) {
if (this.maxSize > 0) {
// check if maximum overflow
if (this.currentProgress > this.maxLength) {
this.currentProgress = this.maxLength;
stepTo(this.maxLength);
if (this.currentProgress > this.maxSize) {
this.currentProgress = this.maxSize;
stepTo(this.maxSize);
return;
}
}
Expand All @@ -76,12 +113,12 @@ public long getCurrentProgress() {

@Override
public void close() {
if (this.maxLength < 0) {
if (this.maxSize < 0) {
return;
}

if (this.currentProgress < this.maxLength) {
stepTo(this.maxLength);
if (this.currentProgress < this.maxSize) {
stepTo(this.maxSize);
}
}

Expand Down
22 changes: 18 additions & 4 deletions cli/src/main/java/com/devonfw/tools/ide/io/FileAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ default void symlink(Path source, Path targetLink) {

/**
* @param source the source {@link Path file or folder} to copy.
* @param target the {@link Path} to copy {@code source} to. See {@link #copy(Path, Path, FileCopyMode)} for details. will always ensure that in the end
* @param target the {@link Path} to copy {@code source} to. See {@link #copy(Path, Path, FileCopyMode)} for details. Will always ensure that in the end
* you will find the same content of {@code source} in {@code target}.
*/
default void copy(Path source, Path target) {
Expand All @@ -105,10 +105,24 @@ default void copy(Path source, Path target) {
* {@code target}. Therefore the result is always clear and easy to predict and understand. Also you can easily rename a file to copy. While
* {@code cp my-file target} may lead to a different result than {@code cp my-file target/} this method will always ensure that in the end you will find
* the same content of {@code source} in {@code target}.
* @param fileOnly - {@code true} if {@code fileOrFolder} is expected to be a file and an exception shall be thrown if it is a directory, {@code false}
* otherwise (copy recursively).
* @param mode the {@link FileCopyMode}.
*/
void copy(Path source, Path target, FileCopyMode fileOnly);
default void copy(Path source, Path target, FileCopyMode mode) {

copy(source, target, mode, PathCopyListener.NONE);
}

/**
* @param source the source {@link Path file or folder} to copy.
* @param target the {@link Path} to copy {@code source} to. Unlike the Linux {@code cp} command this method will not take the filename of {@code source}
* and copy that to {@code target} in case that is an existing folder. Instead it will always be simple and stupid and just copy from {@code source} to
* {@code target}. Therefore the result is always clear and easy to predict and understand. Also you can easily rename a file to copy. While
* {@code cp my-file target} may lead to a different result than {@code cp my-file target/} this method will always ensure that in the end you will find
* the same content of {@code source} in {@code target}.
* @param mode the {@link FileCopyMode}.
* @param listener the {@link PathCopyListener} that will be called for each copied {@link Path}.
*/
void copy(Path source, Path target, FileCopyMode mode, PathCopyListener listener);

/**
* @param archiveFile the {@link Path} to the file to extract.
Expand Down
Loading

0 comments on commit afcaffc

Please sign in to comment.