|
|
@ -633,9 +633,8 @@ public class ArchiveTest extends CLIRepositoryTestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void assertMagic(long offset, byte[] magicBytes, File file) throws Exception { |
|
|
|
private void assertMagic(long offset, byte[] magicBytes, File file) throws Exception { |
|
|
|
BufferedInputStream in = new BufferedInputStream( |
|
|
|
try (BufferedInputStream in = new BufferedInputStream( |
|
|
|
new FileInputStream(file)); |
|
|
|
new FileInputStream(file))) { |
|
|
|
try { |
|
|
|
|
|
|
|
if (offset > 0) { |
|
|
|
if (offset > 0) { |
|
|
|
long skipped = in.skip(offset); |
|
|
|
long skipped = in.skip(offset); |
|
|
|
assertEquals(offset, skipped); |
|
|
|
assertEquals(offset, skipped); |
|
|
@ -644,8 +643,6 @@ public class ArchiveTest extends CLIRepositoryTestCase { |
|
|
|
byte[] actual = new byte[magicBytes.length]; |
|
|
|
byte[] actual = new byte[magicBytes.length]; |
|
|
|
in.read(actual); |
|
|
|
in.read(actual); |
|
|
|
assertArrayEquals(magicBytes, actual); |
|
|
|
assertArrayEquals(magicBytes, actual); |
|
|
|
} finally { |
|
|
|
|
|
|
|
in.close(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -686,23 +683,19 @@ public class ArchiveTest extends CLIRepositoryTestCase { |
|
|
|
private void writeRaw(String filename, byte[] data) |
|
|
|
private void writeRaw(String filename, byte[] data) |
|
|
|
throws IOException { |
|
|
|
throws IOException { |
|
|
|
File path = new File(db.getWorkTree(), filename); |
|
|
|
File path = new File(db.getWorkTree(), filename); |
|
|
|
OutputStream out = new FileOutputStream(path); |
|
|
|
try (OutputStream out = new FileOutputStream(path)) { |
|
|
|
try { |
|
|
|
|
|
|
|
out.write(data); |
|
|
|
out.write(data); |
|
|
|
} finally { |
|
|
|
|
|
|
|
out.close(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static String[] listZipEntries(byte[] zipData) throws IOException { |
|
|
|
private static String[] listZipEntries(byte[] zipData) throws IOException { |
|
|
|
List<String> l = new ArrayList<>(); |
|
|
|
List<String> l = new ArrayList<>(); |
|
|
|
ZipInputStream in = new ZipInputStream( |
|
|
|
try (ZipInputStream in = new ZipInputStream( |
|
|
|
new ByteArrayInputStream(zipData)); |
|
|
|
new ByteArrayInputStream(zipData))) { |
|
|
|
|
|
|
|
|
|
|
|
ZipEntry e; |
|
|
|
ZipEntry e; |
|
|
|
while ((e = in.getNextEntry()) != null) |
|
|
|
while ((e = in.getNextEntry()) != null) |
|
|
|
l.add(e.getName()); |
|
|
|
l.add(e.getName()); |
|
|
|
in.close(); |
|
|
|
} |
|
|
|
return l.toArray(new String[l.size()]); |
|
|
|
return l.toArray(new String[l.size()]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -725,7 +718,7 @@ public class ArchiveTest extends CLIRepositoryTestCase { |
|
|
|
private String[] listTarEntries(byte[] tarData) throws Exception { |
|
|
|
private String[] listTarEntries(byte[] tarData) throws Exception { |
|
|
|
List<String> l = new ArrayList<>(); |
|
|
|
List<String> l = new ArrayList<>(); |
|
|
|
Process proc = spawnAssumingCommandPresent("tar", "tf", "-"); |
|
|
|
Process proc = spawnAssumingCommandPresent("tar", "tf", "-"); |
|
|
|
BufferedReader reader = readFromProcess(proc); |
|
|
|
try (BufferedReader reader = readFromProcess(proc)) { |
|
|
|
OutputStream out = proc.getOutputStream(); |
|
|
|
OutputStream out = proc.getOutputStream(); |
|
|
|
|
|
|
|
|
|
|
|
// Dump tarball to tar stdin in background
|
|
|
|
// Dump tarball to tar stdin in background
|
|
|
@ -739,10 +732,10 @@ public class ArchiveTest extends CLIRepositoryTestCase { |
|
|
|
return l.toArray(new String[l.size()]); |
|
|
|
return l.toArray(new String[l.size()]); |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
writing.get(); |
|
|
|
writing.get(); |
|
|
|
reader.close(); |
|
|
|
|
|
|
|
proc.destroy(); |
|
|
|
proc.destroy(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static String[] zipEntryContent(byte[] zipData, String path) |
|
|
|
private static String[] zipEntryContent(byte[] zipData, String path) |
|
|
|
throws IOException { |
|
|
|
throws IOException { |
|
|
@ -771,7 +764,7 @@ public class ArchiveTest extends CLIRepositoryTestCase { |
|
|
|
throws Exception { |
|
|
|
throws Exception { |
|
|
|
List<String> l = new ArrayList<>(); |
|
|
|
List<String> l = new ArrayList<>(); |
|
|
|
Process proc = spawnAssumingCommandPresent("tar", "Oxf", "-", path); |
|
|
|
Process proc = spawnAssumingCommandPresent("tar", "Oxf", "-", path); |
|
|
|
BufferedReader reader = readFromProcess(proc); |
|
|
|
try (BufferedReader reader = readFromProcess(proc)) { |
|
|
|
OutputStream out = proc.getOutputStream(); |
|
|
|
OutputStream out = proc.getOutputStream(); |
|
|
|
Future<?> writing = writeAsync(out, tarData); |
|
|
|
Future<?> writing = writeAsync(out, tarData); |
|
|
|
|
|
|
|
|
|
|
@ -783,8 +776,8 @@ public class ArchiveTest extends CLIRepositoryTestCase { |
|
|
|
return l.toArray(new String[l.size()]); |
|
|
|
return l.toArray(new String[l.size()]); |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
writing.get(); |
|
|
|
writing.get(); |
|
|
|
reader.close(); |
|
|
|
|
|
|
|
proc.destroy(); |
|
|
|
proc.destroy(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|