mirror of https://github.com/zlatinb/muwire
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 timepull/37/head
parent
5c18b4a141
commit
e27704c1af
|
@ -264,6 +264,7 @@ public class Core {
|
||||||
log.info "initializing folder persistence service"
|
log.info "initializing folder persistence service"
|
||||||
persisterFolderService = new PersisterFolderService(new File(home, "files"), eventBus)
|
persisterFolderService = new PersisterFolderService(new File(home, "files"), eventBus)
|
||||||
eventBus.register(PersisterDoneEvent.class, persisterFolderService)
|
eventBus.register(PersisterDoneEvent.class, persisterFolderService)
|
||||||
|
eventBus.register(FileLoadedEvent.class, persisterFolderService)
|
||||||
eventBus.register(FileHashedEvent.class, persisterFolderService)
|
eventBus.register(FileHashedEvent.class, persisterFolderService)
|
||||||
eventBus.register(FileUnsharedEvent.class, persisterFolderService)
|
eventBus.register(FileUnsharedEvent.class, persisterFolderService)
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ abstract class BasePersisterService extends Service{
|
||||||
Set<Destination> sourceSet = sources.stream().map({ d -> new Destination(d.toString())}).collect Collectors.toSet()
|
Set<Destination> sourceSet = sources.stream().map({ d -> new Destination(d.toString())}).collect Collectors.toSet()
|
||||||
DownloadedFile df = new DownloadedFile(file, ih, pieceSize, sourceSet)
|
DownloadedFile df = new DownloadedFile(file, ih, pieceSize, sourceSet)
|
||||||
df.setComment(json.comment)
|
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)
|
sf.hit(searcher, timestamp, query)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new FileLoadedEvent(loadedFile: sf, sourceClass: this.class)
|
return new FileLoadedEvent(loadedFile: sf, source : "PersisterService")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,5 +6,5 @@ import com.muwire.core.SharedFile
|
||||||
class FileLoadedEvent extends Event {
|
class FileLoadedEvent extends Event {
|
||||||
|
|
||||||
SharedFile loadedFile
|
SharedFile loadedFile
|
||||||
Class sourceClass
|
String source
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,8 +68,9 @@ class PersisterFolderService extends BasePersisterService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void onFileLoadedEvent(FileLoadedEvent loadedEvent) {
|
void onFileLoadedEvent(FileLoadedEvent loadedEvent) {
|
||||||
if(loadedEvent.sourceClass == PersisterService){
|
if(loadedEvent.source == "PersisterService"){
|
||||||
log.info("Migrating persisted file from PersisterService")
|
log.info("Migrating persisted file from PersisterService: "
|
||||||
|
+ loadedEvent.loadedFile.file.absolutePath.toString())
|
||||||
persistFile(loadedEvent.loadedFile)
|
persistFile(loadedEvent.loadedFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,7 +125,7 @@ class PersisterFolderService extends BasePersisterService {
|
||||||
def jsonPath = getJsonPath(sf)
|
def jsonPath = getJsonPath(sf)
|
||||||
|
|
||||||
def startTime = System.currentTimeMillis()
|
def startTime = System.currentTimeMillis()
|
||||||
jsonPath.parent.toFile().mkdir()
|
jsonPath.parent.toFile().mkdirs()
|
||||||
jsonPath.toFile().withPrintWriter { writer ->
|
jsonPath.toFile().withPrintWriter { writer ->
|
||||||
def json = toJson sf
|
def json = toJson sf
|
||||||
json = JsonOutput.toJson(json)
|
json = JsonOutput.toJson(json)
|
||||||
|
|
Loading…
Reference in New Issue