Ignore fetches for a file we are already downloading.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 18 Apr 2013 04:14:08 +0000 (06:14 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 18 Apr 2013 04:14:08 +0000 (06:14 +0200)
src/main/java/net/pterodactylus/xdcc/core/Core.java

index 607246c..0e7d2e7 100644 (file)
@@ -220,6 +220,25 @@ public class Core extends AbstractExecutionThreadService {
                        return;
                }
 
+               /* check if we are already downloading the file? */
+               if (downloads.containsKey(pack.name())) {
+                       Collection<Download> packDownloads = downloads.get(pack.name());
+                       Collection<Download> runningDownloads = FluentIterable.from(packDownloads).filter(FILTER_RUNNING).toSet();
+                       if (!runningDownloads.isEmpty()) {
+                               Download download = runningDownloads.iterator().next();
+                               eventBus.post(new GenericMessage(String.format("File %s is already downloading from %s (%s).", pack.name(), download.bot().name(), download.bot().network().name())));
+                               return;
+                       }
+                       StringBuilder bots = new StringBuilder();
+                       for (Download download : packDownloads) {
+                               if (bots.length() > 0) {
+                                       bots.append(", ");
+                               }
+                               bots.append(download.bot().name()).append(" (").append(download.bot().network().name()).append(')');
+                       }
+                       eventBus.post(new GenericMessage(String.format("File %s is already requested from %d bots (%s).", pack.name(), packDownloads.size(), bots.toString())));
+               }
+
                Download download = new Download(bot, pack);
                downloads.put(pack.name(), download);