]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Use atomic rename
authorChocobozzz <me@florianbigard.com>
Tue, 16 May 2023 08:06:07 +0000 (10:06 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 16 May 2023 08:06:07 +0000 (10:06 +0200)
server/lib/live/live-segment-sha-store.ts
server/lib/object-storage/shared/object-storage-helpers.ts

index 17e0c6a8296227f8a3b980ac150d4c2a611d0044..1a0a93985598721cb4fd5ad17bfc8ed7a1a21c13 100644 (file)
@@ -1,4 +1,4 @@
-import { move, writeJson } from 'fs-extra'
+import { rename, writeJson } from 'fs-extra'
 import PQueue from 'p-queue'
 import { basename } from 'path'
 import { mapToJSON } from '@server/helpers/core-utils'
@@ -72,9 +72,9 @@ class LiveSegmentShaStore {
 
   private writeToDisk () {
     return this.writeQueue.add(async () => {
-      // Atomic write
+      // Atomic write: use rename instead of move that is not atomic
       await writeJson(this.sha256PathTMP, mapToJSON(this.segmentsSha256))
-      await move(this.sha256PathTMP, this.sha256Path, { overwrite: true })
+      await rename(this.sha256PathTMP, this.sha256Path)
 
       if (this.sendToObjectStorage) {
         const url = await storeHLSFileFromPath(this.streamingPlaylist, this.sha256Path)
index f517c5f6940963968aba928dd52fa7cca838f5dc..861c490d79b2b11df88c232d8f2a2cca92c1c85a 100644 (file)
@@ -278,7 +278,7 @@ async function uploadToStorage (options: {
 
   logger.debug(
     'Completed %s%s in bucket %s',
-    bucketInfo.PREFIX, objectStorageKey, bucketInfo.BUCKET_NAME, lTags()
+    bucketInfo.PREFIX, objectStorageKey, bucketInfo.BUCKET_NAME, { ...lTags(), reseponseMetadata: response.$metadata }
   )
 
   return getInternalUrl(bucketInfo, objectStorageKey)