1import fs, { promises } from 'fs'2import { fs1Promises as fsPromises } from './fsPromisesF.mts'3import type { absFileDirPath } from '../../ptDirF.mts'4import { assertDefined } from '../../sharedF/assertsF/assertDefinedF.mts'6const fsCpDel = async (fromPath : absFileDirPath, toPath : absFileDirPath) => {7 try {8 await fsPromises.cp(fromPath, toPath)9 await fsPromises.unlink(fromPath)10 } catch (err) {11 console.trace(err, {fromPath, toPath})12 process.exit(1)13 }14}16export const fsCp = async (fromPath : absFileDirPath, toPath : absFileDirPath) => {17 assertDefined(fromPath)18 assertDefined(toPath)19 if (fromPath == toPath) return20 await fsPromises.cp(fromPath, toPath)21}23export const fsRename = async (fromPath : absFileDirPath, toPath : absFileDirPath) => {24 try {25 await fsPromises.rename(fromPath, toPath)26 } catch (err : unknown) {27 if ((err as NodeJS.ErrnoException).code == 'EXDEV') {28 console.log('warn, cp & delete workaround for cross-disk mv', fromPath, toPath)29 await fsCpDel(fromPath, toPath)30 return31 }32 console.trace(err, {fromPath, toPath})33 process.exit(1)34 }35}37export const read1FileIfExist = async (filePath : absFileDirPath) => {38 try {39 return await promises.readFile(filePath, 'utf-8')40 } catch (err : unknown) {41 if ((err as NodeJS.ErrnoException).code == 'ENOENT') return false42 throw err43 }44}