delete affected collections when unsharing

pull/53/head
Zlatin Balevsky 2020-11-01 20:44:29 +00:00
parent 9831848b73
commit 09a560e05c
No known key found for this signature in database
GPG Key ID: A72832072D525E41
2 changed files with 16 additions and 1 deletions

View File

@ -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")

View File

@ -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<FileCollection> affected = fileRootToCollections.get(infoHash)
if (affected == null || affected.isEmpty()) {
return
}
affected.each { c ->
diskIO.execute({delete(c)} as Runnable)
}
}
}