1
0
Fork 0

Ensure file is flushed before renaming it

This commit is contained in:
Chocobozzz 2024-02-15 09:00:25 +01:00
parent 11458a747c
commit 8758d8ed8f
No known key found for this signature in database
GPG key ID: 583A612D890159BE

View file

@ -7,6 +7,7 @@ import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
import { MStreamingPlaylistVideo } from '@server/types/models/index.js' import { MStreamingPlaylistVideo } from '@server/types/models/index.js'
import { buildSha256Segment } from '../hls.js' import { buildSha256Segment } from '../hls.js'
import { storeHLSFileFromPath } from '../object-storage/index.js' import { storeHLSFileFromPath } from '../object-storage/index.js'
import { JFWriteOptions } from 'jsonfile'
const lTags = loggerTagsFactory('live') const lTags = loggerTagsFactory('live')
@ -76,7 +77,7 @@ class LiveSegmentShaStore {
logger.debug(`Writing segment sha JSON ${this.sha256Path} of ${this.videoUUID} on disk.`, lTags(this.videoUUID)) logger.debug(`Writing segment sha JSON ${this.sha256Path} of ${this.videoUUID} on disk.`, lTags(this.videoUUID))
// Atomic write: use rename instead of move that is not atomic // Atomic write: use rename instead of move that is not atomic
await writeJson(this.sha256PathTMP, mapToJSON(this.segmentsSha256)) await writeJson(this.sha256PathTMP, mapToJSON(this.segmentsSha256), { flush: true } as JFWriteOptions) // FIXME: jsonfile typings
await rename(this.sha256PathTMP, this.sha256Path) await rename(this.sha256PathTMP, this.sha256Path)
if (this.sendToObjectStorage) { if (this.sendToObjectStorage) {