Skip to content

Commit

Permalink
#315 Fix entry removal logic check
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-lingala committed May 3, 2021
1 parent 76a4ba5 commit cd37bb5
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.lingala.zip4j.model.enums.RandomAccessFileMode;
import net.lingala.zip4j.progress.ProgressMonitor;
import net.lingala.zip4j.tasks.RemoveFilesFromZipTask.RemoveFilesFromZipTaskParameters;
import net.lingala.zip4j.util.InternalZipConstants;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -95,7 +96,12 @@ private List<String> filterNonExistingEntries(List<String> filesToRemove) throws

private boolean shouldEntryBeRemoved(FileHeader fileHeaderToBeChecked, List<String> fileNamesToBeRemoved) {
for (String fileNameToBeRemoved : fileNamesToBeRemoved) {
if (fileHeaderToBeChecked.getFileName().equals(fileNameToBeRemoved)) {
// If any of the files to be removed is a directory, check if the fileHeaderToBeChecked is a sub-file or
// a sub-directory of that directory
if (InternalZipConstants.ZIP_FILE_SEPARATOR.endsWith(fileNameToBeRemoved) &&
fileHeaderToBeChecked.getFileName().startsWith(fileNameToBeRemoved)) {
return true;
} else if (fileHeaderToBeChecked.getFileName().equals(fileNameToBeRemoved)) {
return true;
}
}
Expand Down

0 comments on commit cd37bb5

Please sign in to comment.