Only set the insert time after the insert has finished. Fixes #30.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 16 Jan 2011 19:13:58 +0000 (20:13 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 16 Jan 2011 19:13:58 +0000 (20:13 +0100)
src/main/java/net/pterodactylus/sone/core/SoneInserter.java

index fec4e8f..c15b1d0 100644 (file)
@@ -182,7 +182,6 @@ public class SoneInserter extends AbstractService {
                                        } else {
                                                lastModificationTime = System.currentTimeMillis();
                                                modified = true;
-                                               sone.setTime(lastModificationTime);
                                                logger.log(Level.FINE, "Sone %s has been modified, waiting %d seconds before inserting.", new Object[] { sone.getName(), insertionDelay });
                                        }
                                        lastFingerprint = fingerprint;
@@ -199,12 +198,15 @@ public class SoneInserter extends AbstractService {
                                boolean success = false;
                                try {
                                        core.setSoneStatus(sone, SoneStatus.inserting);
+                                       long insertTime = System.currentTimeMillis();
+                                       insertInformation.setTime(insertTime);
                                        FreenetURI finalUri = freenetInterface.insertDirectory(insertInformation.getInsertUri().setKeyType("USK").setSuggestedEdition(0), insertInformation.generateManifestEntries(), "index.html");
                                        /* at this point we might already be stopped. */
                                        if (shouldStop()) {
                                                /* if so, bail out, don’t change anything. */
                                                break;
                                        }
+                                       sone.setTime(insertTime);
                                        sone.setLatestEdition(finalUri.getEdition());
                                        success = true;
                                        logger.log(Level.INFO, "Inserted Sone “%s” at %s.", new Object[] { sone.getName(), finalUri });
@@ -276,6 +278,16 @@ public class SoneInserter extends AbstractService {
                        return (FreenetURI) soneProperties.get("insertUri");
                }
 
+               /**
+                * Sets the time of the Sone at the time of the insert.
+                *
+                * @param time
+                *            The time of the Sone
+                */
+               public void setTime(long time) {
+                       soneProperties.put("time", time);
+               }
+
                //
                // ACTIONS
                //