return;
}
final boolean compress = request.getPartAsStringFailsafe("compress", 128).length() > 0;
final String identifier = file.getFilename() + "-fred-" + System.currentTimeMillis();
final String compatibilityMode = request.getPartAsStringFailsafe("compatibilityMode", 100);
final CompatibilityMode cmode;
if(compatibilityMode.equals(""))
cmode = CompatibilityMode.COMPAT_DEFAULT.intern();
else
cmode = CompatibilityMode.valueOf(compatibilityMode).intern();
String s = request.getPartAsStringFailsafe("overrideSplitfileKey", 65);
final byte[] overrideSplitfileKey;
if(s != null && !s.equals(""))
overrideSplitfileKey = HexUtil.hexToBytes(s);
else
overrideSplitfileKey = null;
final String fnam;
if(insertURI.getKeyType().equals("CHK") || keyType.equals("SSK"))
fnam = file.getFilename();
else
fnam = null;
/* copy bucket data */
final RandomAccessBucket copiedBucket = core.persistentTempBucketFactory.makeBucket(file.getData().size());
BucketTools.copy(file.getData(), copiedBucket);
final CountDownLatch done = new CountDownLatch(1);
try {
core.clientLayerPersister.queue(new PersistentJob() {
@Override
public String toString() {
return "QueueToadlet StartInsert";
}
@Override
public boolean run(ClientContext context) {
try {
final ClientPut clientPut;
try {
clientPut = new ClientPut(fcp.getGlobalForeverClient(), insertURI, identifier, Integer.MAX_VALUE, null, RequestStarter.BULK_SPLITFILE_PRIORITY_CLASS, Persistence.FOREVER, null, false, !compress, -1, UploadFrom.DIRECT, null, file.getContentType(), copiedBucket, null, fnam, false, false, Node.FORK_ON_CACHEABLE_DEFAULT, HighLevelSimpleClientImpl.EXTRA_INSERTS_SINGLE_BLOCK, HighLevelSimpleClientImpl.EXTRA_INSERTS_SPLITFILE_HEADER, false, cmode, overrideSplitfileKey, false, fcp.core);
if(clientPut != null)
try {
fcp.startBlocking(clientPut, context);
} catch (IdentifierCollisionException e) {
Logger.error(this, "Cannot put same file twice in same millisecond");
writePermanentRedirect(ctx, "Done", path());
return false;
}
writePermanentRedirect(ctx, "Done", path());
return true;
} catch (IdentifierCollisionException e) {
Logger.error(this, "Cannot put same file twice in same millisecond");
writePermanentRedirect(ctx, "Done", path());
return false;
} catch (NotAllowedException e) {
writeError(l10n("errorAccessDenied"), l10n("errorAccessDeniedFile", "file", file.getFilename()), ctx, false, true);
return false;
} catch (FileNotFoundException e) {
writeError(l10n("errorNoFileOrCannotRead"), l10n("errorAccessDeniedFile", "file", file.getFilename()), ctx, false, true);
return false;
} catch (MalformedURLException mue1) {
writeError(l10n("errorInvalidURI"), l10n("errorInvalidURIToU"), ctx, false, true);
return false;
} catch (MetadataUnresolvedException e) {
Logger.error(this, "Unresolved metadata in starting insert from data uploaded from browser: "+e, e);
writePermanentRedirect(ctx, "Done", path());
return false;
// FIXME should this be a proper localised message? It shouldn't happen... but we'd like to get reports if it does.
} catch (Throwable t) {
writeInternalError(t, ctx);
return false;
} finally {
done.countDown();
}
} catch (IOException e) {
// Ignore
return false;
} catch (ToadletContextClosedException e) {
// Ignore
return false;
}
}
}, NativeThread.HIGH_PRIORITY+1);
} catch (PersistenceDisabledException e1) {
sendPersistenceDisabledError(ctx);
return;
}
while (done.getCount() > 0) {
try {
done.await();
} catch (InterruptedException e) {
// Ignore
}
}
return;
} else if (request.isPartSet(LocalFileBrowserToadlet.selectFile)) {
final String filename = request.getPartAsStringFailsafe("filename", MAX_FILENAME_LENGTH);
if(logMINOR) Logger.minor(this, "Inserting local file: "+filename);
final File file = new File(filename);
final String identifier = file.getName() + "-fred-" + System.currentTimeMillis();
final String contentType = DefaultMIMETypes.guessMIMEType(filename, false);
final FreenetURI furi;
final String key = request.getPartAsStringFailsafe("key", MAX_KEY_LENGTH);
final boolean compress = request.isPartSet("compress");
final String compatibilityMode = request.getPartAsStringFailsafe("compatibilityMode", 100);
final CompatibilityMode cmode;
if(compatibilityMode.equals(""))
cmode = CompatibilityMode.COMPAT_DEFAULT;
else
cmode = CompatibilityMode.valueOf(compatibilityMode);
String s = request.getPartAsStringFailsafe("overrideSplitfileKey", 65);