Make sure migration from PersisterService works

this.getClass() and this.class kept resolving to Class.
Using a string is much simpler

mkdirs() is also necessary because the directory structure doesn't exist
 when persistFile is called the first time
pull/37/head
LoveIsGrief 2020-01-22 20:59:05 +01:00
parent 5c18b4a141
commit e27704c1af
No known key found for this signature in database
GPG Key ID: E96D1EDFA05345EB
4 changed files with 8 additions and 6 deletions

View File

@ -264,6 +264,7 @@ public class Core {
log.info "initializing folder persistence service"
persisterFolderService = new PersisterFolderService(new File(home, "files"), eventBus)
eventBus.register(PersisterDoneEvent.class, persisterFolderService)
eventBus.register(FileLoadedEvent.class, persisterFolderService)
eventBus.register(FileHashedEvent.class, persisterFolderService)
eventBus.register(FileUnsharedEvent.class, persisterFolderService)

View File

@ -53,7 +53,7 @@ abstract class BasePersisterService extends Service{
Set<Destination> sourceSet = sources.stream().map({ d -> new Destination(d.toString())}).collect Collectors.toSet()
DownloadedFile df = new DownloadedFile(file, ih, pieceSize, sourceSet)
df.setComment(json.comment)
return new FileLoadedEvent(loadedFile : df, sourceClass : this.class)
return new FileLoadedEvent(loadedFile : df, source : "PersisterService")
}
@ -71,7 +71,7 @@ abstract class BasePersisterService extends Service{
sf.hit(searcher, timestamp, query)
}
}
return new FileLoadedEvent(loadedFile: sf, sourceClass: this.class)
return new FileLoadedEvent(loadedFile: sf, source : "PersisterService")
}

View File

@ -6,5 +6,5 @@ import com.muwire.core.SharedFile
class FileLoadedEvent extends Event {
SharedFile loadedFile
Class sourceClass
String source
}

View File

@ -68,8 +68,9 @@ class PersisterFolderService extends BasePersisterService {
}
}
void onFileLoadedEvent(FileLoadedEvent loadedEvent) {
if(loadedEvent.sourceClass == PersisterService){
log.info("Migrating persisted file from PersisterService")
if(loadedEvent.source == "PersisterService"){
log.info("Migrating persisted file from PersisterService: "
+ loadedEvent.loadedFile.file.absolutePath.toString())
persistFile(loadedEvent.loadedFile)
}
}
@ -124,7 +125,7 @@ class PersisterFolderService extends BasePersisterService {
def jsonPath = getJsonPath(sf)
def startTime = System.currentTimeMillis()
jsonPath.parent.toFile().mkdir()
jsonPath.parent.toFile().mkdirs()
jsonPath.toFile().withPrintWriter { writer ->
def json = toJson sf
json = JsonOutput.toJson(json)