Fix: readData must have an atomic part.
This commit is contained in:
parent
c900d2d1d4
commit
ea1c008ded
@ -87,9 +87,6 @@ class RoomChannel {
|
|||||||
public async readData (): Promise<boolean> {
|
public async readData (): Promise<boolean> {
|
||||||
// Reading the data file (see https://livingston.frama.io/peertube-plugin-livechat/fr/technical/data/)
|
// Reading the data file (see https://livingston.frama.io/peertube-plugin-livechat/fr/technical/data/)
|
||||||
|
|
||||||
this.room2Channel.clear()
|
|
||||||
this.channel2Rooms.clear()
|
|
||||||
|
|
||||||
let content: string
|
let content: string
|
||||||
try {
|
try {
|
||||||
content = (await fs.promises.readFile(this.dataFilePath)).toString()
|
content = (await fs.promises.readFile(this.dataFilePath)).toString()
|
||||||
@ -107,6 +104,18 @@ class RoomChannel {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This part must be done atomicly:
|
||||||
|
return this._readData(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _readData is the atomic part of readData:
|
||||||
|
* once the date are read from disk, object data must be emptied and filled atomicly.
|
||||||
|
*/
|
||||||
|
protected _readData (data: any): boolean {
|
||||||
|
this.room2Channel.clear()
|
||||||
|
this.channel2Rooms.clear()
|
||||||
|
|
||||||
if (typeof data !== 'object') {
|
if (typeof data !== 'object') {
|
||||||
this.logger.error('Invalid room-channel data file content')
|
this.logger.error('Invalid room-channel data file content')
|
||||||
return false
|
return false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user