Author: toad
Date: 2006-09-28 20:22:17 +0000 (Thu, 28 Sep 2006)
New Revision: 10555
Modified:
trunk/freenet/src/freenet/client/HighLevelSimpleClient.java
trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
trunk/freenet/src/freenet/client/Metadata.java
trunk/freenet/src/freenet/client/async/ClientPutter.java
trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
trunk/freenet/src/freenet/client/async/SingleFileInserter.java
trunk/freenet/src/freenet/clients/http/QueueToadlet.java
trunk/freenet/src/freenet/clients/http/Toadlet.java
trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
trunk/freenet/src/freenet/clients/http/filter/CSSTokenizerFilter.java
trunk/freenet/src/freenet/frost/message/FrostMessage.java
trunk/freenet/src/freenet/node/NodeARKInserter.java
trunk/freenet/src/freenet/node/TextModeClientInterface.java
trunk/freenet/src/freenet/node/fcp/ClientPut.java
trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java
trunk/freenet/src/freenet/node/fcp/PersistentPut.java
Log:
Single-file inserts can have a filename. If they do, we create a 1-file
manifest with that filename pointing to the content being uploaded.
You can either specify it explicitly with TargetFilename (empty means insert
old style, no filename), or it will be auto-detected (if you are uploading a
CHK) from the filename you upload from, or any filename specified in your key.
Modified: trunk/freenet/src/freenet/client/HighLevelSimpleClient.java
===================================================================
--- trunk/freenet/src/freenet/client/HighLevelSimpleClient.java 2006-09-28
18:40:34 UTC (rev 10554)
+++ trunk/freenet/src/freenet/client/HighLevelSimpleClient.java 2006-09-28
20:22:17 UTC (rev 10555)
@@ -33,9 +33,10 @@
/**
* Blocking insert.
+ * @param filenameHint If set, insert a single-file manifest containing
only this file, under the given filename.
* @throws InserterException If there is an error inserting the data
*/
- public FreenetURI insert(InsertBlock insert, boolean getCHKOnly) throws
InserterException;
+ public FreenetURI insert(InsertBlock insert, boolean getCHKOnly, String
filenameHint) throws InserterException;
/**
* Blocking insert of a redirect.
Modified: trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
===================================================================
--- trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
2006-09-28 18:40:34 UTC (rev 10554)
+++ trunk/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
2006-09-28 20:22:17 UTC (rev 10555)
@@ -120,15 +120,15 @@
return fw.waitForCompletion();
}
- public FreenetURI insert(InsertBlock insert, boolean getCHKOnly) throws
InserterException {
- return insert(insert, getCHKOnly, false);
+ public FreenetURI insert(InsertBlock insert, boolean getCHKOnly, String
filenameHint) throws InserterException {
+ return insert(insert, getCHKOnly, filenameHint, false);
}
- public FreenetURI insert(InsertBlock insert, boolean getCHKOnly,
boolean isMetadata) throws InserterException {
+ public FreenetURI insert(InsertBlock insert, boolean getCHKOnly, String
filenameHint, boolean isMetadata) throws InserterException {
InserterContext context = getInserterContext(true);
PutWaiter pw = new PutWaiter();
ClientPutter put = new ClientPutter(pw, insert.data,
insert.desiredURI, insert.clientMetadata,
- context, core.requestStarters.chkPutScheduler,
core.requestStarters.sskPutScheduler, priorityClass, getCHKOnly, isMetadata,
this, null);
+ context, core.requestStarters.chkPutScheduler,
core.requestStarters.sskPutScheduler, priorityClass, getCHKOnly, isMetadata,
this, null, filenameHint);
put.start();
return pw.waitForCompletion();
}
@@ -147,7 +147,7 @@
}
InsertBlock block = new InsertBlock(b, null, insertURI);
- return insert(block, false, true);
+ return insert(block, false, null, true);
}
public FreenetURI insertManifest(FreenetURI insertURI, HashMap
bucketsByName, String defaultName) throws InserterException {
Modified: trunk/freenet/src/freenet/client/Metadata.java
===================================================================
--- trunk/freenet/src/freenet/client/Metadata.java 2006-09-28 18:40:34 UTC
(rev 10554)
+++ trunk/freenet/src/freenet/client/Metadata.java 2006-09-28 20:22:17 UTC
(rev 10555)
@@ -313,6 +313,8 @@
// Parse the sub-Manifest.
+ Logger.minor(this, "Simple manifest,
"+manifestEntryCount+" entries");
+
for(int i=0;i<manifestEntryCount;i++) {
short nameLength = dis.readShort();
byte[] buf = new byte[nameLength];
@@ -400,7 +402,7 @@
/**
* Create a Metadata object and add manifest entries from the given map.
- * The map can contain either string -> byte[], or string -> map, the
latter
+ * The map can contain either string -> Metadata, or string -> map, the
latter
* indicating subdirs.
*/
public static Metadata mkRedirectionManifestWithMetadata(HashMap dir) {
Modified: trunk/freenet/src/freenet/client/async/ClientPutter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientPutter.java 2006-09-28
18:40:34 UTC (rev 10554)
+++ trunk/freenet/src/freenet/client/async/ClientPutter.java 2006-09-28
20:22:17 UTC (rev 10555)
@@ -19,6 +19,7 @@
final FreenetURI targetURI;
final ClientMetadata cm;
final InserterContext ctx;
+ final String targetFilename;
private ClientPutState currentState;
private boolean finished;
private final boolean getCHKOnly;
@@ -42,10 +43,11 @@
* @param clientContext The client object for purposs of round-robin
client balancing.
* @param stored The progress so far, stored as a SimpleFieldSet.
Advisory; if there
* is an error reading this in, we will restart from scratch.
+ * @param targetFilename If set, create a one-file manifest containing
this filename pointing to this file.
*/
public ClientPutter(ClientCallback client, Bucket data, FreenetURI
targetURI, ClientMetadata cm, InserterContext ctx,
ClientRequestScheduler chkScheduler,
ClientRequestScheduler sskScheduler, short priorityClass, boolean getCHKOnly,
- boolean isMetadata, Object clientContext,
SimpleFieldSet stored) {
+ boolean isMetadata, Object clientContext,
SimpleFieldSet stored, String targetFilename) {
super(priorityClass, chkScheduler, sskScheduler, clientContext);
this.cm = cm;
this.isMetadata = isMetadata;
@@ -57,6 +59,7 @@
this.finished = false;
this.cancelled = false;
this.oldProgress = stored;
+ this.targetFilename = targetFilename;
}
public void start() throws InserterException {
@@ -73,7 +76,7 @@
cancel = this.cancelled;
if(!cancel) {
currentState =
- new SingleFileInserter(this,
this, new InsertBlock(data, cm, targetURI), isMetadata, ctx, false, getCHKOnly,
false, null, false, false);
+ new SingleFileInserter(this,
this, new InsertBlock(data, cm, targetURI), isMetadata, ctx, false, getCHKOnly,
false, null, false, false, targetFilename);
}
}
if(cancel) {
@@ -142,7 +145,11 @@
}
public void onEncode(BaseClientKey key, ClientPutState state) {
- this.uri = key.getURI();
+ synchronized(this) {
+ this.uri = key.getURI();
+ if(targetFilename != null)
+ uri = uri.pushMetaString(targetFilename);
+ }
client.onGeneratedURI(uri, this);
}
Modified: trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
2006-09-28 18:40:34 UTC (rev 10554)
+++ trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
2006-09-28 20:22:17 UTC (rev 10555)
@@ -37,7 +37,7 @@
InsertBlock block =
new InsertBlock(data, cm,
FreenetURI.EMPTY_CHK_URI);
this.origSFI =
- new SingleFileInserter(this, this, block,
false, ctx, false, getCHKOnly, true, null, false, false);
+ new SingleFileInserter(this, this, block,
false, ctx, false, getCHKOnly, true, null, false, false, null);
metadata = null;
}
@@ -432,7 +432,7 @@
block = new InsertBlock(bucket, null, targetURI);
try {
SingleFileInserter metadataInserter =
- new SingleFileInserter(this, this, block,
isMetadata, ctx, false, getCHKOnly, false, baseMetadata,
insertAsArchiveManifest, true);
+ new SingleFileInserter(this, this, block,
isMetadata, ctx, false, getCHKOnly, false, baseMetadata,
insertAsArchiveManifest, true, null);
if(logMINOR) Logger.minor(this, "Inserting main
metadata: "+metadataInserter);
this.metadataPuttersByMetadata.put(baseMetadata,
metadataInserter);
metadataPuttersUnfetchable.put(baseMetadata,
metadataInserter);
@@ -457,7 +457,7 @@
InsertBlock ib = new InsertBlock(b, null,
FreenetURI.EMPTY_CHK_URI);
SingleFileInserter metadataInserter =
- new SingleFileInserter(this, this, ib,
true, ctx, false, getCHKOnly, false, m, false, true);
+ new SingleFileInserter(this, this, ib,
true, ctx, false, getCHKOnly, false, m, false, true, null);
if(logMINOR) Logger.minor(this, "Inserting
subsidiary metadata: "+metadataInserter+" for "+m);
synchronized(this) {
this.metadataPuttersByMetadata.put(m,
metadataInserter);
Modified: trunk/freenet/src/freenet/client/async/SingleFileInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileInserter.java
2006-09-28 18:40:34 UTC (rev 10554)
+++ trunk/freenet/src/freenet/client/async/SingleFileInserter.java
2006-09-28 20:22:17 UTC (rev 10555)
@@ -2,6 +2,7 @@
import java.io.IOException;
import java.net.MalformedURLException;
+import java.util.HashMap;
import freenet.client.InsertBlock;
import freenet.client.InserterContext;
@@ -47,6 +48,7 @@
private final boolean reportMetadataOnly;
public final Object token;
private final boolean freeData; // this is being set, but never read ???
+ private final String targetFilename;
/**
* @param parent
@@ -59,11 +61,13 @@
* @param reportMetadataOnly If true, don't insert the metadata, just
report it.
* @param insertAsArchiveManifest If true, insert the metadata as an
archive manifest.
* @param freeData If true, free the data when possible.
+ * @param targetFilename
* @throws InserterException
*/
SingleFileInserter(BaseClientPutter parent, PutCompletionCallback cb,
InsertBlock block,
boolean metadata, InserterContext ctx, boolean
dontCompress,
- boolean getCHKOnly, boolean reportMetadataOnly, Object
token, boolean insertAsArchiveManifest, boolean freeData) throws
InserterException {
+ boolean getCHKOnly, boolean reportMetadataOnly, Object
token, boolean insertAsArchiveManifest,
+ boolean freeData, String targetFilename) throws
InserterException {
this.reportMetadataOnly = reportMetadataOnly;
this.token = token;
this.parent = parent;
@@ -74,6 +78,7 @@
this.getCHKOnly = getCHKOnly;
this.insertAsArchiveManifest = insertAsArchiveManifest;
this.freeData = freeData;
+ this.targetFilename = targetFilename;
logMINOR = Logger.shouldLog(Logger.MINOR, this);
}
@@ -189,7 +194,7 @@
if(block.getData().size() > Integer.MAX_VALUE)
throw new
InserterException(InserterException.INTERNAL_ERROR, "2GB+ should not encode to
one block!", null);
- boolean noMetadata = (block.clientMetadata == null) ||
block.clientMetadata.isTrivial();
+ boolean noMetadata = ((block.clientMetadata == null) ||
block.clientMetadata.isTrivial()) && targetFilename == null;
if(metadata && !noMetadata) {
throw new
InserterException(InserterException.INTERNAL_ERROR, "MIME type set for a
metadata insert!", null);
}
@@ -208,7 +213,7 @@
// Insert single block, then insert pointer to it
if(reportMetadataOnly) {
SingleBlockInserter dataPutter = new
SingleBlockInserter(parent, data, codecNumber, FreenetURI.EMPTY_CHK_URI, ctx,
cb, metadata, (int)origSize, -1, getCHKOnly, true, true, token);
- Metadata meta = new
Metadata(insertAsArchiveManifest ? Metadata.ZIP_MANIFEST :
Metadata.SIMPLE_REDIRECT, dataPutter.getURI(), block.clientMetadata);
+ Metadata meta =
makeMetadata(dataPutter.getURI());
cb.onMetadata(meta, this);
cb.onTransition(this, dataPutter);
dataPutter.schedule();
@@ -217,7 +222,7 @@
MultiPutCompletionCallback mcb =
new MultiPutCompletionCallback(cb,
parent, token);
SingleBlockInserter dataPutter = new
SingleBlockInserter(parent, data, codecNumber, FreenetURI.EMPTY_CHK_URI, ctx,
mcb, metadata, (int)origSize, -1, getCHKOnly, true, false, token);
- Metadata meta = new
Metadata(insertAsArchiveManifest ? Metadata.ZIP_MANIFEST :
Metadata.SIMPLE_REDIRECT, dataPutter.getURI(), block.clientMetadata);
+ Metadata meta =
makeMetadata(dataPutter.getURI());
Bucket metadataBucket;
try {
metadataBucket =
BucketTools.makeImmutableBucket(ctx.bf, meta.writeToByteArray());
@@ -259,6 +264,16 @@
}
}
+ private Metadata makeMetadata(FreenetURI uri) {
+ Metadata meta = new Metadata(insertAsArchiveManifest ?
Metadata.ZIP_MANIFEST : Metadata.SIMPLE_REDIRECT, uri, block.clientMetadata);
+ if(targetFilename != null) {
+ HashMap hm = new HashMap();
+ hm.put(targetFilename, meta);
+ meta = Metadata.mkRedirectionManifestWithMetadata(hm);
+ }
+ return meta;
+ }
+
private ClientPutState createInserter(BaseClientPutter parent, Bucket
data, short compressionCodec, FreenetURI uri,
InserterContext ctx, PutCompletionCallback cb, boolean
isMetadata, int sourceLength, int token, boolean getCHKOnly,
boolean addToParent) throws InserterException {
@@ -423,6 +438,12 @@
onFailure(e, state);
return;
}
+ if(targetFilename != null) {
+ HashMap hm = new HashMap();
+ hm.put(targetFilename, meta);
+ meta =
Metadata.mkRedirectionManifestWithMetadata(hm);
+ }
+
Bucket metadataBucket;
try {
metadataBucket =
BucketTools.makeImmutableBucket(ctx.bf, meta.writeToByteArray());
@@ -440,7 +461,7 @@
InsertBlock newBlock = new InsertBlock(metadataBucket,
null, block.desiredURI);
try {
synchronized(this) {
- metadataPutter = new
SingleFileInserter(parent, this, newBlock, true, ctx, false, getCHKOnly, false,
token, false, true);
+ metadataPutter = new
SingleFileInserter(parent, this, newBlock, true, ctx, false, getCHKOnly, false,
token, false, true, null);
if(!dataFetchable) return;
}
if(logMINOR) Logger.minor(this, "Putting
metadata on "+metadataPutter+" from "+sfi+"
("+((SplitFileInserter)sfi).getLength()+")");
Modified: trunk/freenet/src/freenet/clients/http/QueueToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/QueueToadlet.java 2006-09-28
18:40:34 UTC (rev 10554)
+++ trunk/freenet/src/freenet/clients/http/QueueToadlet.java 2006-09-28
20:22:17 UTC (rev 10555)
@@ -170,11 +170,16 @@
}
boolean compress =
request.getPartAsString("compress", 128).length() > 0;
String identifier = file.getFilename() +
"-fred-" + System.currentTimeMillis();
+ String fnam;
+ if(insertURI.getKeyType().equals("CHK"))
+ fnam = file.getFilename();
+ else
+ fnam = null;
/* copy bucket data */
Bucket copiedBucket =
core.persistentEncryptedTempBucketFactory.makeBucket(file.getData().size());
BucketTools.copy(file.getData(), copiedBucket);
try {
- ClientPut clientPut = new
ClientPut(fcp.getGlobalClient(), insertURI, identifier, Integer.MAX_VALUE,
RequestStarter.BULK_SPLITFILE_PRIORITY_CLASS, ClientRequest.PERSIST_FOREVER,
null, false, !compress, -1, ClientPutMessage.UPLOAD_FROM_DIRECT, null,
file.getContentType(), copiedBucket, null);
+ ClientPut clientPut = new
ClientPut(fcp.getGlobalClient(), insertURI, identifier, Integer.MAX_VALUE,
RequestStarter.BULK_SPLITFILE_PRIORITY_CLASS, ClientRequest.PERSIST_FOREVER,
null, false, !compress, -1, ClientPutMessage.UPLOAD_FROM_DIRECT, null,
file.getContentType(), copiedBucket, null, fnam);
clientPut.start();
fcp.forceStorePersistentRequests();
} catch (IdentifierCollisionException e) {
@@ -188,7 +193,7 @@
String identifier = file.getName() + "-fred-" +
System.currentTimeMillis();
String contentType =
DefaultMIMETypes.guessMIMEType(filename, false);
try {
- ClientPut clientPut = new
ClientPut(fcp.getGlobalClient(), new FreenetURI("CHK@"), identifier,
Integer.MAX_VALUE, RequestStarter.BULK_SPLITFILE_PRIORITY_CLASS,
ClientRequest.PERSIST_FOREVER, null, false, false, -1,
ClientPutMessage.UPLOAD_FROM_DISK, file, contentType, new FileBucket(file,
true, false, false, false), null);
+ ClientPut clientPut = new
ClientPut(fcp.getGlobalClient(), new FreenetURI("CHK@"), identifier,
Integer.MAX_VALUE, RequestStarter.BULK_SPLITFILE_PRIORITY_CLASS,
ClientRequest.PERSIST_FOREVER, null, false, false, -1,
ClientPutMessage.UPLOAD_FROM_DISK, file, contentType, new FileBucket(file,
true, false, false, false), null, file.getName());
clientPut.start();
fcp.forceStorePersistentRequests();
} catch (IdentifierCollisionException e) {
Modified: trunk/freenet/src/freenet/clients/http/Toadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/Toadlet.java 2006-09-28 18:40:34 UTC
(rev 10554)
+++ trunk/freenet/src/freenet/clients/http/Toadlet.java 2006-09-28 20:22:17 UTC
(rev 10555)
@@ -98,10 +98,10 @@
return client.fetch(uri, maxSize);
}
- FreenetURI insert(InsertBlock insert, boolean getCHKOnly) throws
InserterException {
+ FreenetURI insert(InsertBlock insert, String filenameHint, boolean
getCHKOnly) throws InserterException {
// For now, just run it blocking.
insert.desiredURI.checkInsertURI();
- return client.insert(insert, getCHKOnly);
+ return client.insert(insert, getCHKOnly, filenameHint);
}
/**
Modified: trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java 2006-09-28
18:40:34 UTC (rev 10554)
+++ trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java 2006-09-28
20:22:17 UTC (rev 10555)
@@ -259,9 +259,16 @@
HTMLNode pageNode =
ctx.getPageMaker().getPageNode("Insertion");
HTMLNode contentNode =
ctx.getPageMaker().getContentNode(pageNode);
HTMLNode content;
+ String filenameHint = null;
+ if(key.getKeyType().equals("CHK")) {
+ String[] metas =
key.getAllMetaStrings();
+ if(metas != null && metas.length > 1) {
+ filenameHint = metas.toString();
+ }
+ }
InsertBlock block = new InsertBlock(bucket,
contentType, key);
try {
- key = this.insert(block, false);
+ key = this.insert(block, filenameHint,
false);
HTMLNode infobox =
contentNode.addChild(ctx.getPageMaker().getInfobox("infobox-success", "Insert
Succeeded"));
content =
ctx.getPageMaker().getContentNode(infobox);
content.addChild("#", "The key ");
Modified: trunk/freenet/src/freenet/clients/http/filter/CSSTokenizerFilter.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/filter/CSSTokenizerFilter.java
2006-09-28 18:40:34 UTC (rev 10554)
+++ trunk/freenet/src/freenet/clients/http/filter/CSSTokenizerFilter.java
2006-09-28 20:22:17 UTC (rev 10555)
@@ -1,8 +1,8 @@
-/* The following code was generated by JFlex 1.4.1 on 28/09/06 17:52 */
+/* The following code was generated by JFlex 1.4.1 on 28/09/06 20:13 */
/* This code is part of Freenet. It is distributed under the GNU General
* Public License, version 2 (or at your option any later version). See
- * http://www.gnu.org/ for further details of the GPL. */
+ * http://www.gnu.org/ for further details of the GPL. */
package freenet.clients.http.filter;
import java.io.*;
import java.util.*;
@@ -14,7 +14,7 @@
/**
* This class is a scanner generated by
* <a href="http://www.jflex.de/">JFlex</a> 1.4.1
- * on 28/09/06 17:52 from the specification file
+ * on 28/09/06 20:13 from the specification file
* <tt>freenet/clients/http/filter/CSSTokenizerFilter.jflex</tt>
*/
class CSSTokenizerFilter {
Modified: trunk/freenet/src/freenet/frost/message/FrostMessage.java
===================================================================
--- trunk/freenet/src/freenet/frost/message/FrostMessage.java 2006-09-28
18:40:34 UTC (rev 10554)
+++ trunk/freenet/src/freenet/frost/message/FrostMessage.java 2006-09-28
20:22:17 UTC (rev 10555)
@@ -291,7 +291,7 @@
// try inserting the message with the key
try {
- returnKey = client.insert(block, false); // I don't know what
that 'false' is
+ returnKey = client.insert(block, false, null); // I don't know
what that 'false' is
}
catch (InserterException e)
{
Modified: trunk/freenet/src/freenet/node/NodeARKInserter.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeARKInserter.java 2006-09-28 18:40:34 UTC
(rev 10554)
+++ trunk/freenet/src/freenet/node/NodeARKInserter.java 2006-09-28 20:22:17 UTC
(rev 10555)
@@ -134,7 +134,7 @@
inserter = new ClientPutter(this, b, uri,
new ClientMetadata("text/plain") /* it
won't quite fit in an SSK anyway */,
node.clientCore.makeClient((short)0).getInserterContext(true),
-
node.clientCore.requestStarters.chkPutScheduler,
node.clientCore.requestStarters.sskPutScheduler,
RequestStarter.INTERACTIVE_PRIORITY_CLASS, false, false, this, null);
+
node.clientCore.requestStarters.chkPutScheduler,
node.clientCore.requestStarters.sskPutScheduler,
RequestStarter.INTERACTIVE_PRIORITY_CLASS, false, false, this, null, null);
try {
Modified: trunk/freenet/src/freenet/node/TextModeClientInterface.java
===================================================================
--- trunk/freenet/src/freenet/node/TextModeClientInterface.java 2006-09-28
18:40:34 UTC (rev 10554)
+++ trunk/freenet/src/freenet/node/TextModeClientInterface.java 2006-09-28
20:22:17 UTC (rev 10555)
@@ -354,7 +354,6 @@
printHeader(out);
return false;
} else if(uline.startsWith("PUT:") || (getCHKOnly =
uline.startsWith("GETCHK:"))) {
- // Just insert to local store
if(getCHKOnly)
line = line.substring(("GETCHK:").length());
else
@@ -378,7 +377,7 @@
FreenetURI uri;
try {
- uri = client.insert(block, getCHKOnly);
+ uri = client.insert(block, getCHKOnly, null);
} catch (InserterException e) {
outsb.append("Error: "+e.getMessage());
if(e.uri != null)
@@ -501,7 +500,7 @@
InsertBlock block = new InsertBlock(fb, new
ClientMetadata(mimeType), FreenetURI.EMPTY_CHK_URI);
startTime = System.currentTimeMillis();
- FreenetURI uri = client.insert(block, getCHKOnly);
+ FreenetURI uri = client.insert(block, getCHKOnly, f.getName());
// FIXME depends on CHK's still being renamable
//uri = uri.setDocName(f.getName());
Modified: trunk/freenet/src/freenet/node/fcp/ClientPut.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientPut.java 2006-09-28 18:40:34 UTC
(rev 10554)
+++ trunk/freenet/src/freenet/node/fcp/ClientPut.java 2006-09-28 20:22:17 UTC
(rev 10555)
@@ -33,6 +33,8 @@
private final ClientMetadata clientMetadata;
/** We store the size of inserted data before freeing it */
private long finishedSize;
+ /** Filename if the file has one */
+ private final String targetFilename;
/**
* Creates a new persistent insert.
@@ -77,8 +79,9 @@
public ClientPut(FCPClient globalClient, FreenetURI uri, String
identifier, int verbosity,
short priorityClass, short persistenceType, String
clientToken, boolean getCHKOnly,
boolean dontCompress, int maxRetries, short
uploadFromType, File origFilename, String contentType,
- Bucket data, FreenetURI redirectTarget) throws
IdentifierCollisionException {
+ Bucket data, FreenetURI redirectTarget, String
targetFilename) throws IdentifierCollisionException {
super(uri, identifier, verbosity, null, globalClient,
priorityClass, persistenceType, null, true, getCHKOnly, dontCompress,
maxRetries);
+ this.targetFilename = targetFilename;
this.uploadFrom = uploadFromType;
this.origFilename = origFilename;
// Now go through the fields one at a time
@@ -116,7 +119,7 @@
if(logMINOR) Logger.minor(this, "data = "+data+", uploadFrom =
"+ClientPutMessage.uploadFromString(uploadFrom));
inserter = new ClientPutter(this, data, uri, cm,
ctx,
client.core.requestStarters.chkPutScheduler,
client.core.requestStarters.sskPutScheduler, priorityClass,
- getCHKOnly, isMetadata, client, null);
+ getCHKOnly, isMetadata, client, null,
targetFilename);
if(persistenceType != PERSIST_CONNECTION) {
FCPMessage msg = persistentTagMessage();
client.queueClientRequestMessage(msg, 0);
@@ -127,6 +130,7 @@
super(message.uri, message.identifier, message.verbosity,
handler,
message.priorityClass, message.persistenceType,
message.clientToken, message.global,
message.getCHKOnly, message.dontCompress,
message.maxRetries);
+ this.targetFilename = message.targetFilename;
boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
this.uploadFrom = message.uploadFromType;
this.origFilename = message.origFilename;
@@ -170,7 +174,7 @@
if(logMINOR) Logger.minor(this, "data = "+data+", uploadFrom =
"+ClientPutMessage.uploadFromString(uploadFrom));
inserter = new ClientPutter(this, data, uri, cm,
ctx,
client.core.requestStarters.chkPutScheduler,
client.core.requestStarters.sskPutScheduler, priorityClass,
- getCHKOnly, isMetadata, client, null);
+ getCHKOnly, isMetadata, client, null,
targetFilename);
if(persistenceType != PERSIST_CONNECTION) {
FCPMessage msg = persistentTagMessage();
client.queueClientRequestMessage(msg, 0);
@@ -213,6 +217,8 @@
boolean isMetadata = false;
+ targetFilename = fs.get("TargetFilename");
+
if(uploadFrom == ClientPutMessage.UPLOAD_FROM_DISK) {
origFilename = new File(fs.get("Filename"));
data = new FileBucket(origFilename, true, false, false,
false);
@@ -258,11 +264,12 @@
}
this.clientMetadata = cm;
inserter = new ClientPutter(this, data, uri, cm, ctx,
client.core.requestStarters.chkPutScheduler,
- client.core.requestStarters.sskPutScheduler,
priorityClass, getCHKOnly, isMetadata, client, fs.subset("progress"));
+ client.core.requestStarters.sskPutScheduler,
priorityClass, getCHKOnly, isMetadata, client, fs.subset("progress"),
targetFilename);
if(persistenceType != PERSIST_CONNECTION) {
FCPMessage msg = persistentTagMessage();
client.queueClientRequestMessage(msg, 0);
}
+
}
public void start() {
@@ -310,6 +317,8 @@
SimpleFieldSet sfs = inserter.getProgressFieldset();
fs.put("progress", sfs);
}
+ if(targetFilename != null)
+ fs.put("TargetFilename", targetFilename);
return fs;
}
@@ -320,7 +329,7 @@
protected FCPMessage persistentTagMessage() {
return new PersistentPut(identifier, uri, verbosity,
priorityClass, uploadFrom, targetURI,
persistenceType, origFilename,
clientMetadata.getMIMEType(), client.isGlobalQueue,
- getDataSize(), clientToken, started,
ctx.maxInsertRetries);
+ getDataSize(), clientToken, started,
ctx.maxInsertRetries, targetFilename);
}
protected String getTypeName() {
Modified: trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java 2006-09-28
18:40:34 UTC (rev 10554)
+++ trunk/freenet/src/freenet/node/fcp/ClientPutMessage.java 2006-09-28
20:22:17 UTC (rev 10555)
@@ -51,12 +51,15 @@
final File origFilename;
final boolean global;
final FreenetURI redirectTarget;
+ /** Filename (hint for the final filename) */
+ final String targetFilename;
public static final short UPLOAD_FROM_DIRECT = 0;
public static final short UPLOAD_FROM_DISK = 1;
public static final short UPLOAD_FROM_REDIRECT = 2;
public ClientPutMessage(SimpleFieldSet fs) throws
MessageInvalidException {
+ String fnam = null;
identifier = fs.get("Identifier");
if(identifier == null)
throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "No Identifier",
null);
@@ -64,7 +67,13 @@
String u = fs.get("URI");
if(u == null)
throw new
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "No URI",
identifier);
- uri = new FreenetURI(fs.get("URI"));
+ FreenetURI uu = new FreenetURI(fs.get("URI"));
+ String[] metas = uu.getAllMetaStrings();
+ if(metas != null && metas.length == 1) {
+ fnam = metas[0];
+ uu = uu.setMetaString(null);
+ } // if >1, will fail later
+ uri = uu;
} catch (MalformedURLException e) {
throw new
MessageInvalidException(ProtocolErrorMessage.URI_PARSE_ERROR, e.getMessage(),
identifier);
}
@@ -131,6 +140,8 @@
this.bucket = fileBucket;
this.origFilename = f;
redirectTarget = null;
+ if(fnam == null)
+ fnam = origFilename.getName();
} else if(uploadFrom.equalsIgnoreCase("redirect")) {
uploadFromType = UPLOAD_FROM_REDIRECT;
String target = fs.get("TargetURI");
@@ -162,6 +173,19 @@
throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing Persistence field: "+persistenceString, identifier);
}
clientToken = fs.get("ClientToken");
+ String f = fs.get("TargetFilename");
+ if(f != null)
+ fnam = f;
+ if(fnam != null && fnam.indexOf('/') > -1) {
+ throw new
MessageInvalidException(ProtocolErrorMessage.INVALID_FIELD, "TargetFilename
must not contain slashes", identifier);
+ }
+ if(fnam != null && fnam.length() == 0) {
+ fnam = null; // Deliberate override to tell us not to
create one.
+ }
+ if(uri.getKeyType().equals("CHK"))
+ targetFilename = fnam;
+ else
+ targetFilename = null;
}
public SimpleFieldSet getFieldSet() {
Modified: trunk/freenet/src/freenet/node/fcp/PersistentPut.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/PersistentPut.java 2006-09-28
18:40:34 UTC (rev 10554)
+++ trunk/freenet/src/freenet/node/fcp/PersistentPut.java 2006-09-28
20:22:17 UTC (rev 10555)
@@ -27,11 +27,12 @@
final String token;
final boolean started;
final int maxRetries;
+ final String targetFilename;
public PersistentPut(String identifier, FreenetURI uri, int verbosity,
short priorityClass, short uploadFrom, FreenetURI
targetURI,
short persistenceType, File origFilename, String
mimeType,
- boolean global, long size, String clientToken, boolean
started, int maxRetries) {
+ boolean global, long size, String clientToken, boolean
started, int maxRetries, String targetFilename) {
this.identifier = identifier;
this.uri = uri;
this.verbosity = verbosity;
@@ -46,6 +47,7 @@
this.token = clientToken;
this.started = started;
this.maxRetries = maxRetries;
+ this.targetFilename = targetFilename;
}
public SimpleFieldSet getFieldSet() {
@@ -69,6 +71,8 @@
fs.put("ClientToken", token);
fs.put("Started", started);
fs.put("MaxRetries", maxRetries);
+ if(targetFilename != null)
+ fs.put("TargetFilename", targetFilename);
return fs;
}