Skip to content

Commit

Permalink
Showing 2 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
@@ -67,6 +67,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">Precompile regualr expression in ArArchiveInputStream.isBSDLongName(String).</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Precompile regular expression in ArArchiveInputStream.isGNULongName(String).</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Precompile regular expression in TarArchiveEntry.parseInstantFromDecimalSeconds(String).</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Precompile regular expression in ChangeSet.addDeletion(Change).</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot">Bump org.slf4j:slf4j-api from 2.0.8 to 2.0.9 #413.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump commons-io:commons-io from 2.13.0 to 2.15.0.</action>
13 changes: 5 additions & 8 deletions src/main/java/org/apache/commons/compress/changes/ChangeSet.java
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.regex.Pattern;

import org.apache.commons.compress.archivers.ArchiveEntry;

@@ -71,16 +72,14 @@ public void add(final ArchiveEntry pEntry, final InputStream pInput, final boole
* the change which should result in an addition
*/
private void addAddition(final Change pChange) {
if (Change.TYPE_ADD != pChange.type() ||
pChange.getInput() == null) {
if (Change.TYPE_ADD != pChange.type() || pChange.getInput() == null) {
return;
}

if (!changes.isEmpty()) {
for (final Iterator<Change> it = changes.iterator(); it.hasNext();) {
final Change change = it.next();
if (change.type() == Change.TYPE_ADD
&& change.getEntry() != null) {
if (change.type() == Change.TYPE_ADD && change.getEntry() != null) {
final ArchiveEntry entry = change.getEntry();

if (entry.equals(pChange.getEntry())) {
@@ -110,20 +109,18 @@ private void addDeletion(final Change pChange) {
return;
}
final String source = pChange.targetFile();

final Pattern pattern = Pattern.compile(source + "/.*");
if (source != null && !changes.isEmpty()) {
for (final Iterator<Change> it = changes.iterator(); it.hasNext();) {
final Change change = it.next();
if (change.type() == Change.TYPE_ADD
&& change.getEntry() != null) {
final String target = change.getEntry().getName();

if (target == null) {
continue;
}

if (Change.TYPE_DELETE == pChange.type() && source.equals(target) ||
Change.TYPE_DELETE_DIR == pChange.type() && target.matches(source + "/.*")) {
Change.TYPE_DELETE_DIR == pChange.type() && pattern.matcher(target).matches()) {
it.remove();
}
}

0 comments on commit e2f64df

Please sign in to comment.