Use move instead rename
authorChocobozzz <me@florianbigard.com>
Tue, 11 Dec 2018 14:12:38 +0000 (15:12 +0100)
committerChocobozzz <me@florianbigard.com>
Tue, 11 Dec 2018 14:12:38 +0000 (15:12 +0100)
To avoid EXDEV errors

server/controllers/api/videos/import.ts
server/helpers/captions-utils.ts
server/lib/job-queue/handlers/video-import.ts
server/lib/schedulers/videos-redundancy-scheduler.ts
server/lib/video-transcoding.ts

index 099ab7b8d6aafb07b0fcdc18cb1e25dc6f6f93bf..98366cd82cff70235288cd37330cf243fb2a9471 100644 (file)
@@ -21,7 +21,7 @@ import { VideoChannelModel } from '../../../models/video/video-channel'
 import * as Bluebird from 'bluebird'
 import * as parseTorrent from 'parse-torrent'
 import { getSecureTorrentName } from '../../../helpers/utils'
-import { readFile, rename } from 'fs-extra'
+import { readFile, move } from 'fs-extra'
 
 const auditLogger = auditLoggerFactory('video-imports')
 const videoImportsRouter = express.Router()
@@ -71,7 +71,7 @@ async function addTorrentImport (req: express.Request, res: express.Response, to
 
     // Rename the torrent to a secured name
     const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, getSecureTorrentName(torrentName))
-    await rename(torrentfile.path, newTorrentPath)
+    await move(torrentfile.path, newTorrentPath)
     torrentfile.path = newTorrentPath
 
     const buf = await readFile(torrentfile.path)
index 660dce65c3c5c0292dd3e680775c3356542300a7..1aafbf8056abd79b9cd3ab3a9f4eee191ac6a560 100644 (file)
@@ -2,7 +2,7 @@ import { join } from 'path'
 import { CONFIG } from '../initializers'
 import { VideoCaptionModel } from '../models/video/video-caption'
 import * as srt2vtt from 'srt-to-vtt'
-import { createReadStream, createWriteStream, remove, rename } from 'fs-extra'
+import { createReadStream, createWriteStream, remove, move } from 'fs-extra'
 
 async function moveAndProcessCaptionFile (physicalFile: { filename: string, path: string }, videoCaption: VideoCaptionModel) {
   const videoCaptionsDir = CONFIG.STORAGE.CAPTIONS_DIR
@@ -13,7 +13,7 @@ async function moveAndProcessCaptionFile (physicalFile: { filename: string, path
     await convertSrtToVtt(physicalFile.path, destination)
     await remove(physicalFile.path)
   } else { // Just move the vtt file
-    await rename(physicalFile.path, destination)
+    await move(physicalFile.path, destination)
   }
 
   // This is important in case if there is another attempt in the retry process
index 51a0b5faf5a2bc347a515addbec764491839963a..63aacff98fcfea4cd4c290518db8da38867fe974 100644 (file)
@@ -14,7 +14,7 @@ import { federateVideoIfNeeded } from '../../activitypub'
 import { VideoModel } from '../../../models/video/video'
 import { downloadWebTorrentVideo } from '../../../helpers/webtorrent'
 import { getSecureTorrentName } from '../../../helpers/utils'
-import { remove, rename, stat } from 'fs-extra'
+import { remove, move, stat } from 'fs-extra'
 
 type VideoImportYoutubeDLPayload = {
   type: 'youtube-dl'
@@ -139,7 +139,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: Vide
 
     // Move file
     videoDestFile = join(CONFIG.STORAGE.VIDEOS_DIR, videoImport.Video.getVideoFilename(videoFile))
-    await rename(tempVideoPath, videoDestFile)
+    await move(tempVideoPath, videoDestFile)
     tempVideoPath = null // This path is not used anymore
 
     // Process thumbnail
index 2a99a665d12fd05d755c5360f734532f2f7a54b5..15e094d39dba5fedcebeb126a9564c36f23948fa 100644 (file)
@@ -6,7 +6,7 @@ import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
 import { VideoFileModel } from '../../models/video/video-file'
 import { downloadWebTorrentVideo } from '../../helpers/webtorrent'
 import { join } from 'path'
-import { rename } from 'fs-extra'
+import { move } from 'fs-extra'
 import { getServerActor } from '../../helpers/utils'
 import { sendCreateCacheFile, sendUpdateCacheFile } from '../activitypub/send'
 import { getVideoCacheFileActivityPubUrl } from '../activitypub/url'
@@ -146,7 +146,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
       const tmpPath = await downloadWebTorrentVideo({ magnetUri }, VIDEO_IMPORT_TIMEOUT)
 
       const destPath = join(CONFIG.STORAGE.REDUNDANCY_DIR, video.getVideoFilename(file))
-      await rename(tmpPath, destPath)
+      await move(tmpPath, destPath)
 
       const createdModel = await VideoRedundancyModel.create({
         expiresOn: this.buildNewExpiration(redundancy.minLifetime),
index a78de61e5673052955b8da1d7c48f36441a8b4f8..4460f46e418d5809fbda6ecdf1ce8db112254908 100644 (file)
@@ -1,7 +1,7 @@
 import { CONFIG } from '../initializers'
 import { extname, join } from 'path'
 import { getVideoFileFPS, getVideoFileResolution, transcode } from '../helpers/ffmpeg-utils'
-import { copy, remove, rename, stat } from 'fs-extra'
+import { copy, remove, move, stat } from 'fs-extra'
 import { logger } from '../helpers/logger'
 import { VideoResolution } from '../../shared/models/videos'
 import { VideoFileModel } from '../models/video/video-file'
@@ -30,7 +30,7 @@ async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFi
     inputVideoFile.set('extname', newExtname)
 
     const videoOutputPath = video.getVideoFilePath(inputVideoFile)
-    await rename(videoTranscodedPath, videoOutputPath)
+    await move(videoTranscodedPath, videoOutputPath)
     const stats = await stat(videoOutputPath)
     const fps = await getVideoFileFPS(videoOutputPath)