Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 1304 invoked from network); 17 Apr 2009 05:39:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 17 Apr 2009 05:39:02 -0000 Received: (qmail 93113 invoked by uid 500); 17 Apr 2009 05:39:02 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 93004 invoked by uid 500); 17 Apr 2009 05:39:01 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 92995 invoked by uid 99); 17 Apr 2009 05:39:01 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Apr 2009 05:39:01 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Apr 2009 05:38:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B8A302388A35; Fri, 17 Apr 2009 05:38:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r765850 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/changes/ChangeSet.java test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java Date: Fri, 17 Apr 2009 05:38:38 -0000 To: commits@commons.apache.org From: grobmeier@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090417053838.B8A302388A35@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: grobmeier Date: Fri Apr 17 05:38:38 2009 New Revision: 765850 URL: http://svn.apache.org/viewvc?rev=765850&view=rev Log: prevent adding an ArchiveEntry with same name twice to an ChangeSet Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSet.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSet.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSet.java?rev=765850&r1=765849&r2=765850&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSet.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSet.java Fri Apr 17 05:38:38 2009 @@ -65,10 +65,39 @@ * the datastream to add */ public void add(final ArchiveEntry pEntry, final InputStream pInput) { - changes.add(new Change(pEntry, pInput)); + addAddition(new Change(pEntry, pInput)); } /** + * Adds an addition change. + * + * @param pChange + * the change which should result in an addition + */ + private void addAddition(Change pChange) { + if (Change.TYPE_ADD != pChange.type() || + pChange.getInput() == null) { + return; + } + + if (!changes.isEmpty()) { + for (Iterator it = changes.iterator(); it.hasNext();) { + Change change = (Change) it.next(); + if (change.type() == Change.TYPE_ADD + && change.getEntry() != null) { + ArchiveEntry entry = change.getEntry(); + + if(entry.equals(pChange.getEntry())) { + it.remove(); + break; + } + } + } + } + changes.add(pChange); + } + + /** * Adds an delete change. * * @param pChange Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java?rev=765850&r1=765849&r2=765850&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java Fri Apr 17 05:38:38 2009 @@ -67,6 +67,38 @@ } /** + * Adds an ArchiveEntry with the same name two times. + * Only the latest addition should be found in the ChangeSet, + * the first add should be replaced. + * + * @throws Exception + */ + public void testAddChangeTwice() throws Exception { + InputStream in = null; + InputStream in2 = null; + try { + in = new FileInputStream(getFile("test.txt")); + in2 = new FileInputStream(getFile("test2.xml")); + + ArchiveEntry e = new ZipArchiveEntry("test.txt"); + ArchiveEntry e2 = new ZipArchiveEntry("test.txt"); + + ChangeSet changes = new ChangeSet(); + changes.add(e, in); + changes.add(e2, in2); + + assertEquals(1, changes.getChanges().size()); + Change c = (Change)changes.getChanges().iterator().next(); + assertEquals(in2, c.getInput()); + } finally { + if (in != null) + in.close(); + if (in2 != null) + in2.close(); + } + } + + /** * Tries to delete the folder "bla" from an archive file. This should result in * the deletion of bla/*, which actually means bla/test4.xml should be * removed from the archive. The file something/bla (without ending, named