diff --git a/server/services/rTorrent/clientGatewayService.ts b/server/services/rTorrent/clientGatewayService.ts index ab566392..5c0266d8 100644 --- a/server/services/rTorrent/clientGatewayService.ts +++ b/server/services/rTorrent/clientGatewayService.ts @@ -61,7 +61,7 @@ class RTorrentClientGatewayService extends ClientGatewayService { throw accessDeniedError(); } - createDirectory(destinationPath); + await createDirectory(destinationPath); // Each torrent is sent individually because rTorrent might have small // XMLRPC request size limit. This allows the user to send files reliably. @@ -99,7 +99,7 @@ class RTorrentClientGatewayService extends ClientGatewayService { throw accessDeniedError(); } - createDirectory(destinationPath); + await createDirectory(destinationPath); const methodCalls: MultiMethodCalls = urls.map((url) => { const additionalCalls: Array = []; diff --git a/server/util/fileUtil.ts b/server/util/fileUtil.ts index 17bda2c9..263dc8fc 100644 --- a/server/util/fileUtil.ts +++ b/server/util/fileUtil.ts @@ -38,14 +38,21 @@ export const sanitizePath = (input: string) => { return path.resolve(input).replace(controlRe, ''); }; -export const createDirectory = (directoryPath: string) => { - if (directoryPath) { - fs.mkdir(directoryPath, {recursive: true}, (error) => { - if (error) { - console.trace('Error creating directory.', error); - } - }); - } +export const createDirectory = (directoryPath: string): Promise => { + return new Promise((resolve, reject) => { + if (directoryPath) { + fs.mkdir(directoryPath, {recursive: true}, (error) => { + if (error) { + console.trace('Error creating directory.', error); + reject(); + return; + } + resolve(); + }); + } else { + reject(); + } + }); }; export const getDirectoryList = async (inputPath: string) => {