aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Hayden <andrewhayden@google.com>2016-05-12 11:40:42 +0100
committerAndrew Hayden <andrewhayden@google.com>2016-05-12 11:40:42 +0100
commitd5ab575b01ebc980c2e6054647e133cb47dc4081 (patch)
treec504bb11f1425b3679d93f015b84cd8536251287
parentec0fc6394e5abd1dbd47fe58d2988b997bac60dc (diff)
downloadarchive-patcher-nougat-mr2.3-release.tar.gz
Sync to 8ffe39d965862e3659c68208efa9147adcaea3bb.android-cts_7.1_r1android-cts-7.1_r9android-cts-7.1_r8android-cts-7.1_r7android-cts-7.1_r6android-cts-7.1_r5android-cts-7.1_r4android-cts-7.1_r3android-cts-7.1_r29android-cts-7.1_r28android-cts-7.1_r27android-cts-7.1_r26android-cts-7.1_r25android-cts-7.1_r24android-cts-7.1_r23android-cts-7.1_r22android-cts-7.1_r21android-cts-7.1_r20android-cts-7.1_r2android-cts-7.1_r19android-cts-7.1_r18android-cts-7.1_r17android-cts-7.1_r16android-cts-7.1_r15android-cts-7.1_r14android-cts-7.1_r13android-cts-7.1_r12android-cts-7.1_r11android-cts-7.1_r10android-cts-7.1_r1android-7.1.2_r9android-7.1.2_r8android-7.1.2_r6android-7.1.2_r5android-7.1.2_r4android-7.1.2_r39android-7.1.2_r38android-7.1.2_r37android-7.1.2_r36android-7.1.2_r33android-7.1.2_r32android-7.1.2_r30android-7.1.2_r3android-7.1.2_r29android-7.1.2_r28android-7.1.2_r27android-7.1.2_r25android-7.1.2_r24android-7.1.2_r23android-7.1.2_r2android-7.1.2_r19android-7.1.2_r18android-7.1.2_r17android-7.1.2_r16android-7.1.2_r15android-7.1.2_r14android-7.1.2_r13android-7.1.2_r12android-7.1.2_r11android-7.1.2_r10android-7.1.2_r1android-7.1.1_r9android-7.1.1_r8android-7.1.1_r7android-7.1.1_r61android-7.1.1_r60android-7.1.1_r6android-7.1.1_r59android-7.1.1_r58android-7.1.1_r57android-7.1.1_r56android-7.1.1_r55android-7.1.1_r54android-7.1.1_r53android-7.1.1_r52android-7.1.1_r51android-7.1.1_r50android-7.1.1_r49android-7.1.1_r48android-7.1.1_r47android-7.1.1_r46android-7.1.1_r45android-7.1.1_r44android-7.1.1_r43android-7.1.1_r42android-7.1.1_r41android-7.1.1_r40android-7.1.1_r4android-7.1.1_r39android-7.1.1_r38android-7.1.1_r35android-7.1.1_r33android-7.1.1_r32android-7.1.1_r31android-7.1.1_r3android-7.1.1_r28android-7.1.1_r27android-7.1.1_r26android-7.1.1_r25android-7.1.1_r24android-7.1.1_r23android-7.1.1_r22android-7.1.1_r21android-7.1.1_r20android-7.1.1_r2android-7.1.1_r17android-7.1.1_r16android-7.1.1_r15android-7.1.1_r14android-7.1.1_r13android-7.1.1_r12android-7.1.1_r11android-7.1.1_r10android-7.1.1_r1android-7.1.0_r7android-7.1.0_r6android-7.1.0_r5android-7.1.0_r4android-7.1.0_r3android-7.1.0_r2android-7.1.0_r1nougat-mr2.3-releasenougat-mr2.2-releasenougat-mr2.1-releasenougat-mr2-security-releasenougat-mr2-releasenougat-mr2-pixel-releasenougat-mr2-devnougat-mr1.8-releasenougat-mr1.7-releasenougat-mr1.6-releasenougat-mr1.5-releasenougat-mr1.4-releasenougat-mr1.3-releasenougat-mr1.2-releasenougat-mr1.1-releasenougat-mr1-volantis-releasenougat-mr1-security-releasenougat-mr1-releasenougat-mr1-flounder-releasenougat-mr1-devnougat-mr1-cts-releasenougat-dr1-release
This pulls in a bugfix that is needed by Phonesky: https://github.com/andrewhayden/archive-patcher/issues/6 BUG=26179455 Change-Id: I5e26e7640c8a9383baf780d379ef25c99f5e08f1
-rw-r--r--README.version4
-rw-r--r--applier/src/main/java/com/google/archivepatcher/applier/FileByFileV1DeltaApplier.java24
-rw-r--r--applier/src/test/java/com/google/archivepatcher/applier/FileByFileV1DeltaApplierTest.java62
3 files changed, 54 insertions, 36 deletions
diff --git a/README.version b/README.version
index 3359ef1..e2809f8 100644
--- a/README.version
+++ b/README.version
@@ -1,5 +1,5 @@
-URL: https://github.com/andrewhayden/archive-patcher/archive/5b806288f0ad7db536cc420a6b3b4d655be96cfb.zip
-Version: 5b806288f0ad7db536cc420a6b3b4d655be96cfb
+URL: https://github.com/andrewhayden/archive-patcher/archive/8ffe39d965862e3659c68208efa9147adcaea3bb.zip
+Version: 8ffe39d965862e3659c68208efa9147adcaea3bb
BugComponent: 129875
Owners: andrewhayden, admo
diff --git a/applier/src/main/java/com/google/archivepatcher/applier/FileByFileV1DeltaApplier.java b/applier/src/main/java/com/google/archivepatcher/applier/FileByFileV1DeltaApplier.java
index 63dbd82..d0a578b 100644
--- a/applier/src/main/java/com/google/archivepatcher/applier/FileByFileV1DeltaApplier.java
+++ b/applier/src/main/java/com/google/archivepatcher/applier/FileByFileV1DeltaApplier.java
@@ -83,25 +83,19 @@ public class FileByFileV1DeltaApplier implements DeltaApplier {
// takes up the rest of the patch stream - so there is no need to examine the list of
// DeltaDescriptors in the patch at all.
long deltaLength = plan.getDeltaDescriptors().get(0).getDeltaLength();
- PartiallyCompressingOutputStream recompressingNewBlobOut = null;
DeltaApplier deltaApplier = getDeltaApplier();
// Don't close this stream, as it is just a limiting wrapper.
@SuppressWarnings("resource")
LimitedInputStream limitedDeltaIn = new LimitedInputStream(deltaIn, deltaLength);
- try {
- recompressingNewBlobOut =
- new PartiallyCompressingOutputStream(
- plan.getDeltaFriendlyNewFileRecompressionPlan(),
- newBlobOut,
- DEFAULT_COPY_BUFFER_SIZE);
- deltaApplier.applyDelta(deltaFriendlyOldBlob, limitedDeltaIn, recompressingNewBlobOut);
- } finally {
- try {
- recompressingNewBlobOut.close();
- } catch (Exception ignored) {
- // Nothing
- }
- }
+ // Don't close this stream, as it would close the underlying OutputStream (that we don't own).
+ @SuppressWarnings("resource")
+ PartiallyCompressingOutputStream recompressingNewBlobOut =
+ new PartiallyCompressingOutputStream(
+ plan.getDeltaFriendlyNewFileRecompressionPlan(),
+ newBlobOut,
+ DEFAULT_COPY_BUFFER_SIZE);
+ deltaApplier.applyDelta(deltaFriendlyOldBlob, limitedDeltaIn, recompressingNewBlobOut);
+ recompressingNewBlobOut.flush();
}
/**
diff --git a/applier/src/test/java/com/google/archivepatcher/applier/FileByFileV1DeltaApplierTest.java b/applier/src/test/java/com/google/archivepatcher/applier/FileByFileV1DeltaApplierTest.java
index b2ebf93..8cf75fd 100644
--- a/applier/src/test/java/com/google/archivepatcher/applier/FileByFileV1DeltaApplierTest.java
+++ b/applier/src/test/java/com/google/archivepatcher/applier/FileByFileV1DeltaApplierTest.java
@@ -35,6 +35,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* Tests for {@link FileByFileV1DeltaApplier}.
@@ -50,7 +51,7 @@ public class FileByFileV1DeltaApplierTest {
// delta-friendly new file := UNCOMPRESSED_HEADER + UNCOMPRESSED_NEW_CONTENT +
// UNCOMPRESSED_TRAILER
// new file := UNCOMPRESSED_HEADER + COMPRESSED_NEW_CONTENT + UNCOMPRESSED_TRAILIER
- // NB: The patch *applietr* is agnostic to the format of the file, and so it doesn't have to be a
+ // NB: The patch *applier* is agnostic to the format of the file, and so it doesn't have to be a
// valid zip or zip-like archive.
private static final JreDeflateParameters PARAMS1 = JreDeflateParameters.of(6, 0, true);
private static final String OLD_CONTENT = "This is Content the Old";
@@ -93,10 +94,26 @@ public class FileByFileV1DeltaApplierTest {
*/
private byte[] oldFileBytes;
+ /**
+ * Again, for debugging test issues, it is convenient to be able to see these bytes in the
+ * debugger instead of on the filesystem.
+ */
private byte[] expectedDeltaFriendlyOldFileBytes;
+ /**
+ * To mock the dependency on bsdiff, a subclass of FileByFileV1DeltaApplier is made that always
+ * returns a testing delta applier. This delta applier asserts that the old content is as
+ * expected, and "patches" it by simply writing the expected *new* content to the output stream.
+ */
+ private FileByFileV1DeltaApplier fakeApplier;
+
@Before
public void setUp() throws IOException {
+ // Creates the following resources:
+ // 1. The old file, on disk (and in-memory, for convenience).
+ // 2. The new file, in memory only (for comparing results at the end).
+ // 3. The patch, in memory.
+
File tempFile = File.createTempFile("foo", "bar");
tempDir = tempFile.getParentFile();
tempFile.delete();
@@ -130,6 +147,14 @@ public class FileByFileV1DeltaApplierTest {
// Finally, write the patch that should transform old to new
patchBytes = writePatch();
+
+ // Initialize fake delta applier to mock out dependency on bsdiff
+ fakeApplier = new FileByFileV1DeltaApplier(tempDir) {
+ @Override
+ protected DeltaApplier getDeltaApplier() {
+ return new FakeDeltaApplier();
+ }
+ };
}
/**
@@ -219,28 +244,27 @@ public class FileByFileV1DeltaApplierTest {
@Test
public void testApplyDelta() throws IOException {
// Test all aspects of patch apply: copying, uncompressing and recompressing ranges.
- //
- // To mock the dependency on bsdiff, a subclass of FileByFileV1DeltaApplier is made that always
- // returns a testing delta applier. This delta applier asserts that the old content is as
- // expected, and "patches" it by simply writing the expected *new* content to the output stream.
- //
- // The test harness creates the following resources:
- // 1. The old file, on disk (and in-memory, for convenience).
- // 2. The new file, in memory only (for comparing results at the end).
- // 3. The patch, in memory.
- //
// This test uses the subclasses applier to apply the test patch to the old file, producing the
// new file. Along the way the entry is uncompressed, altered by the testing delta applier, and
// recompressed. It's deceptively simple below, but this is a lot of moving parts.
- FileByFileV1DeltaApplier applier =
- new FileByFileV1DeltaApplier(tempDir) {
- @Override
- protected DeltaApplier getDeltaApplier() {
- return new FakeDeltaApplier();
- }
- };
ByteArrayOutputStream actualNewBlobOut = new ByteArrayOutputStream();
- applier.applyDelta(oldFile, new ByteArrayInputStream(patchBytes), actualNewBlobOut);
+ fakeApplier.applyDelta(oldFile, new ByteArrayInputStream(patchBytes), actualNewBlobOut);
+ Assert.assertArrayEquals(expectedNewBytes, actualNewBlobOut.toByteArray());
+ }
+
+ @Test
+ public void testApplyDelta_DoesntCloseStream() throws IOException {
+ // Test for https://github.com/andrewhayden/archive-patcher/issues/6
+ final AtomicBoolean closed = new AtomicBoolean(false);
+ ByteArrayOutputStream actualNewBlobOut = new ByteArrayOutputStream() {
+ @Override
+ public void close() throws IOException {
+ closed.set(true);
+ }
+ };
+ fakeApplier.applyDelta(oldFile, new ByteArrayInputStream(patchBytes), actualNewBlobOut);
Assert.assertArrayEquals(expectedNewBytes, actualNewBlobOut.toByteArray());
+ Assert.assertFalse(closed.get());
}
+
}