From e08aa2356df939b2dba56cc7142254fe28b887c3 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Sat, 1 Jun 2024 08:06:44 +0100 Subject: [PATCH] Use fsp for promises --- .../file/copyMoveFolderContent/1.0.0/index.ts | 4 ++-- .../file/copyToDirectory/1.0.0/index.ts | 4 ++-- .../file/copyToWorkDirectory/1.0.0/index.ts | 4 ++-- .../file/deleteFile/1.0.0/index.ts | 11 ++++++----- .../handbrake/handbrakeCustomArguments/1.0.0/index.ts | 4 ++-- .../handbrake/handbrakeCustomArguments/2.0.0/index.ts | 4 ++-- .../input/inputFile/1.0.0/index.ts | 6 +++--- FlowPluginsTs/FlowHelpers/1.0.0/classicPlugins.ts | 4 ++-- FlowPluginsTs/FlowHelpers/1.0.0/fileMoveOrCopy.ts | 8 ++++---- FlowPluginsTs/FlowHelpers/1.0.0/fileUtils.ts | 4 ++-- 10 files changed, 27 insertions(+), 26 deletions(-) diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/copyMoveFolderContent/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/copyMoveFolderContent/1.0.0/index.ts index 3d2ed09..ca4615f 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/copyMoveFolderContent/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/copyMoveFolderContent/1.0.0/index.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { getContainer, getFileAbosluteDir, getSubStem, } from '../../../../FlowHelpers/1.0.0/fileUtils'; @@ -188,7 +188,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { sourceDir = getFileAbosluteDir(args.inputFileObj._id); } - let filesInDir = (await fs.readdir(sourceDir)) + let filesInDir = (await fsp.readdir(sourceDir)) .map((row) => ({ source: `${sourceDir}/${row}`, destination: normJoinPath({ diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/copyToDirectory/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/copyToDirectory/1.0.0/index.ts index 6d19860..a5bf4fd 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/copyToDirectory/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/copyToDirectory/1.0.0/index.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { getContainer, getFileName, getSubStem } from '../../../../FlowHelpers/1.0.0/fileUtils'; import { IpluginDetails, @@ -126,7 +126,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { args.deps.fsextra.ensureDirSync(outputPath); - await fs.copyFile(args.inputFileObj._id, ouputFilePath); + await fsp.copyFile(args.inputFileObj._id, ouputFilePath); return { outputFileObj: { diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/copyToWorkDirectory/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/copyToWorkDirectory/1.0.0/index.ts index 04458d1..00f8b22 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/copyToWorkDirectory/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/copyToWorkDirectory/1.0.0/index.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { getContainer, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils'; import { IpluginDetails, @@ -67,7 +67,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { args.deps.fsextra.ensureDirSync(outputPath); - await fs.copyFile(args.inputFileObj._id, ouputFilePath); + await fsp.copyFile(args.inputFileObj._id, ouputFilePath); return { outputFileObj: { diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/deleteFile/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/deleteFile/1.0.0/index.ts index 1969c22..e403d9c 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/deleteFile/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/deleteFile/1.0.0/index.ts @@ -1,4 +1,5 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; + import { IpluginDetails, IpluginInputArgs, @@ -64,21 +65,21 @@ const plugin = async (args: IpluginInputArgs): Promise => { if (fileToDelete === 'workingFile') { args.jobLog(`Deleting working file ${args.inputFileObj._id}`); - await fs.unlink(args.inputFileObj._id); + await fsp.unlink(args.inputFileObj._id); } else if (fileToDelete === 'originalFile') { args.jobLog(`Deleting original file ${args.originalLibraryFile._id}`); - await fs.unlink(args.originalLibraryFile._id); + await fsp.unlink(args.originalLibraryFile._id); } const fileDir = getFileAbosluteDir(args.originalLibraryFile._id); if (deleteParentFolderIfEmpty) { args.jobLog(`Checking if folder ${fileDir} is empty`); - const files = await fs.readdir(fileDir); + const files = await fsp.readdir(fileDir); if (files.length === 0) { args.jobLog(`Deleting empty folder ${fileDir}`); - await fs.rmdir(fileDir); + await fsp.rmdir(fileDir); } else { args.jobLog(`Folder ${fileDir} is not empty, skipping delete`); } diff --git a/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/1.0.0/index.ts index 1b97c87..e44dd1b 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/1.0.0/index.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils'; import { IpluginDetails, @@ -99,7 +99,7 @@ const plugin = async (args:IpluginInputArgs):Promise => { if (presetString.trim() !== '') { const preset = JSON.parse(presetString); - await fs.writeFile(presetPath, JSON.stringify(preset, null, 2)); + await fsp.writeFile(presetPath, JSON.stringify(preset, null, 2)); cliArgs.push('--preset-import-file'); cliArgs.push(presetPath); cliArgs.push('-Z'); diff --git a/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/2.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/2.0.0/index.ts index 6ac4355..546517b 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/2.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/2.0.0/index.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils'; import { IpluginDetails, @@ -142,7 +142,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { if (useJsonPreset) { const preset = JSON.parse(presetString); - await fs.writeFile(presetPath, JSON.stringify(preset, null, 2)); + await fsp.writeFile(presetPath, JSON.stringify(preset, null, 2)); cliArgs.push('--preset-import-file'); cliArgs.push(presetPath); cliArgs.push('-Z'); diff --git a/FlowPluginsTs/CommunityFlowPlugins/input/inputFile/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/input/inputFile/1.0.0/index.ts index 0dc18a0..b6b220e 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/input/inputFile/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/input/inputFile/1.0.0/index.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { IpluginDetails, @@ -86,7 +86,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { const checkReadWrite = async (location: string) => { try { - await fs.access(location, fs.constants.R_OK); + await fsp.access(location, fsp.constants.R_OK); } catch (err) { args.jobLog(JSON.stringify(err)); if (pauseNodeIfAccessChecksFail) { @@ -97,7 +97,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { } try { - await fs.access(location, fs.constants.W_OK); + await fsp.access(location, fsp.constants.W_OK); } catch (err) { args.jobLog(JSON.stringify(err)); if (pauseNodeIfAccessChecksFail) { diff --git a/FlowPluginsTs/FlowHelpers/1.0.0/classicPlugins.ts b/FlowPluginsTs/FlowHelpers/1.0.0/classicPlugins.ts index 5ccf331..22ee25c 100644 --- a/FlowPluginsTs/FlowHelpers/1.0.0/classicPlugins.ts +++ b/FlowPluginsTs/FlowHelpers/1.0.0/classicPlugins.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { getContainer, getFileName, getPluginWorkDir, getScanTypes, } from './fileUtils'; @@ -43,7 +43,7 @@ export const runClassicPlugin = async (args:IpluginInputArgs, type:'filter'|'tra let pluginSrcStr = ''; if (pluginSource === 'Community') { classicPlugin = args.deps.importFresh(relativePluginPath); - pluginSrcStr = await fs.readFile(absolutePath, 'utf8'); + pluginSrcStr = await fsp.readFile(absolutePath, 'utf8'); } else { // eslint-disable-next-line no-await-in-loop const res = await args.deps.axiosMiddleware('api/v2/read-plugin', { diff --git a/FlowPluginsTs/FlowHelpers/1.0.0/fileMoveOrCopy.ts b/FlowPluginsTs/FlowHelpers/1.0.0/fileMoveOrCopy.ts index d3a4871..809d558 100644 --- a/FlowPluginsTs/FlowHelpers/1.0.0/fileMoveOrCopy.ts +++ b/FlowPluginsTs/FlowHelpers/1.0.0/fileMoveOrCopy.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { getFileSize } from './fileUtils'; import { IpluginInputArgs } from './interfaces/interfaces'; @@ -48,7 +48,7 @@ const tryMove = async ({ let error = false; try { - await fs.rename(sourcePath, destinationPath); + await fsp.rename(sourcePath, destinationPath); } catch (err) { error = true; args.jobLog(`File move error: ${JSON.stringify(err)}`); @@ -157,7 +157,7 @@ const tryNormalCopy = async ({ let error = false; try { - await fs.copyFile(sourcePath, destinationPath); + await fsp.copyFile(sourcePath, destinationPath); } catch (err) { error = true; args.jobLog(`File copy error: ${JSON.stringify(err)}`); @@ -186,7 +186,7 @@ const cleanSourceFile = async ({ }) => { try { args.jobLog(`Deleting source file ${sourcePath}`); - await fs.unlink(sourcePath); + await fsp.unlink(sourcePath); } catch (err) { args.jobLog(`Failed to delete source file ${sourcePath}: ${JSON.stringify(err)}`); } diff --git a/FlowPluginsTs/FlowHelpers/1.0.0/fileUtils.ts b/FlowPluginsTs/FlowHelpers/1.0.0/fileUtils.ts index a7f4cfe..9879e7a 100644 --- a/FlowPluginsTs/FlowHelpers/1.0.0/fileUtils.ts +++ b/FlowPluginsTs/FlowHelpers/1.0.0/fileUtils.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { IpluginInputArgs } from './interfaces/interfaces'; export const getContainer = (filePath: string): string => { @@ -37,7 +37,7 @@ export const getSubStem = ({ }; export const getFileSize = async (file:string):Promise => { - const stats = await fs.stat(file); + const stats = await fsp.stat(file); const { size } = stats; return size; };