File size: 718 Bytes
5dfc565
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import path from "node:path"
import tmpDir from "temp-dir"
import { pendingFilesDirFilePath } from "../config.mts"
import { moveFile } from "./moveFile.mts"

// a function to move a file to the pending file directory
// this implementation is safe to use on a Hugging Face Space
// for instance when copying from one disk to another
// (we cannot use fs.rename in that case)
export const moveFileFromTmpToPending = async (tmpFileName: string, pendingFileName?: string) => {
  if (!pendingFileName) {
    pendingFileName = tmpFileName
  }
  const tmpFilePath = path.join(tmpDir, tmpFileName)
  const pendingFilePath = path.join(pendingFilesDirFilePath, pendingFileName)

  await moveFile(tmpFilePath, pendingFilePath)
}