}
}
private void handleTARArchive(ArchiveStoreContext ctx, FreenetURI key, InputStream data, String element, ArchiveExtractCallback callback, MutableBoolean gotElement, boolean throwAtExit, ClientContext context) throws ArchiveFailureException, ArchiveRestartException {
if(logMINOR) Logger.minor(this, "Handling a TAR Archive");
TarArchiveInputStream tarIS = null;
try {
tarIS = new TarArchiveInputStream(data);
// MINOR: Assumes the first entry in the tarball is a directory.
ArchiveEntry entry;
byte[] buf = new byte[32768];
HashSet<String> names = new HashSet<String>();
boolean gotMetadata = false;
outerTAR: while(true) {
try {
entry = tarIS.getNextEntry();
} catch (IllegalArgumentException e) {
// Annoyingly, it can throw this on some corruptions...
throw new ArchiveFailureException("Error reading archive: "+e.getMessage(), e);
}
if(entry == null) break;
if(entry.isDirectory()) continue;
String name = stripLeadingSlashes(entry.getName());
if(names.contains(name)) {
Logger.error(this, "Duplicate key "+name+" in archive "+key);
continue;
}
long size = entry.getSize();
if(name.equals(".metadata"))
gotMetadata = true;
if(size > maxArchivedFileSize && !name.equals(element)) {
addErrorElement(ctx, key, name, "File too big: "+size+" greater than current archived file size limit "+maxArchivedFileSize, true);
} else {
// Read the element
long realLen = 0;
Bucket output = tempBucketFactory.makeBucket(size);
OutputStream out = output.getOutputStream();
try {
int readBytes;
while((readBytes = tarIS.read(buf)) > 0) {
out.write(buf, 0, readBytes);
readBytes += realLen;
if(readBytes > maxArchivedFileSize) {
addErrorElement(ctx, key, name, "File too big: "+maxArchivedFileSize+" greater than current archived file size limit "+maxArchivedFileSize, true);
out.close();