diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index bf28cb16..fa0e0cdc 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -304,6 +304,7 @@ public class Core { register(UICollectionDeletedEvent.class, collectionManager) register(UIDownloadCollectionEvent.class, collectionManager) register(FileDownloadedEvent.class, collectionManager) + register(FileUnsharedEvent.class, collectionManager) } log.info("initializing mesh manager") diff --git a/core/src/main/groovy/com/muwire/core/collections/CollectionManager.groovy b/core/src/main/groovy/com/muwire/core/collections/CollectionManager.groovy index d8b14691..ec4edb7f 100644 --- a/core/src/main/groovy/com/muwire/core/collections/CollectionManager.groovy +++ b/core/src/main/groovy/com/muwire/core/collections/CollectionManager.groovy @@ -18,6 +18,7 @@ import com.muwire.core.MuWireSettings import com.muwire.core.files.AllFilesLoadedEvent import com.muwire.core.files.FileDownloadedEvent import com.muwire.core.files.FileManager +import com.muwire.core.files.FileUnsharedEvent import groovy.util.logging.Log import net.i2p.data.Base64 @@ -209,7 +210,8 @@ class CollectionManager { PayloadAndIH pih = infoHash(collection) String hashB64 = Base64.encode(pih.infoHash.getRoot()) String fileName = "${hashB64}_${collection.author.getHumanReadableName()}_${collection.timestamp}.mwcollection" - + + log.fine("deleting $fileName") File file = new File(localCollections, fileName) file.delete() @@ -259,4 +261,16 @@ class CollectionManager { addToIndex(e.collectionInfoHash, collection) } } + + synchronized void onFileUnsharedEvent(FileUnsharedEvent e) { + InfoHash infoHash = new InfoHash(e.unsharedFile.getRoot()) + Set affected = fileRootToCollections.get(infoHash) + if (affected == null || affected.isEmpty()) { + return + } + affected.each { c -> + diskIO.execute({delete(c)} as Runnable) + } + + } }