Skip to content
Snippets Groups Projects
Commit 2c61d655 authored by Yogmatee Roochun's avatar Yogmatee Roochun
Browse files

#1168 : Ensured that file renaming occurs on FTP, even for files that cannot be extracted

parent ef33c433
No related branches found
No related tags found
3 merge requests!380Pipeline changes,!379Build step added for the master branch,!378k8s release
...@@ -75,8 +75,6 @@ const tidyUp = async (filePath, tmpPath, manId, isError) => { ...@@ -75,8 +75,6 @@ const tidyUp = async (filePath, tmpPath, manId, isError) => {
} }
if (isError) { if (isError) {
logger.info(`Error in Bulk import process for ${filePath}`) logger.info(`Error in Bulk import process for ${filePath}`)
logger.info(`File has been moved to ${updatedFilepath}`)
// await updateFTP(updatedFilepath, submitter)
} else { } else {
logger.info( logger.info(
`Finished Bulk import process for ${filePath} as manuscript ${manId}.`, `Finished Bulk import process for ${filePath} as manuscript ${manId}.`,
...@@ -86,7 +84,7 @@ const tidyUp = async (filePath, tmpPath, manId, isError) => { ...@@ -86,7 +84,7 @@ const tidyUp = async (filePath, tmpPath, manId, isError) => {
}) })
}) })
} catch (e) { } catch (e) {
logger.error('Error while tidying up after another error!') logger.error(`An error has happened while processing file ${fileName}`)
} }
return Journal.knex().destroy() return Journal.knex().destroy()
} }
...@@ -181,7 +179,7 @@ const runProcess = async (packagePath, submitter) => { ...@@ -181,7 +179,7 @@ const runProcess = async (packagePath, submitter) => {
logger.info(`Starting Bulk Import Process for ${packagePath}`) logger.info(`Starting Bulk Import Process for ${packagePath}`)
packageName = path.basename(packagePath) packageName = path.basename(packagePath)
tmpPath = await createTempDir() tmpPath = await createTempDir()
const tmpPathExt = await extractFiles(packagePath, tmpPath) const tmpPathExt = await extractFiles(packagePath, tmpPath, submitter)
// rename file - append .start suffix // rename file - append .start suffix
suffixedFilePath = await fileUtils.renameFileSuffix(packagePath) suffixedFilePath = await fileUtils.renameFileSuffix(packagePath)
const parsedInfo = await parseManifest(tmpPathExt, packageName) const parsedInfo = await parseManifest(tmpPathExt, packageName)
...@@ -222,15 +220,16 @@ const runProcess = async (packagePath, submitter) => { ...@@ -222,15 +220,16 @@ const runProcess = async (packagePath, submitter) => {
} }
} }
const extractFiles = (source, dest) => const extractFiles = (source, dest, submitter) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const cmd = `tar vzxf ${source} -C ${dest} --xform='s#^.+/##x'` // the xform removes all directories const cmd = `tar vzxf ${source} -C ${dest} --xform='s#^.+/##x'` // the xform removes all directories
exec(cmd, async err => { exec(cmd, async err => {
if (err) { if (err) {
logger.error('Error extracting FTP bulk upload files')
// node couldn't execute the command // node couldn't execute the command
await tidyUp(source, dest, '', true) logger.error(`Error extracting FTP bulk upload file: ${source}`)
logger.error(`${source} moved to Error folder`) const updatedFilepath = await tidyUp(source, dest, '', true)
logger.info(`File ${source} has been moved to ${updatedFilepath}`)
await updateFTP(updatedFilepath, submitter)
reject(err) reject(err)
} }
resolve(dest) resolve(dest)
...@@ -855,6 +854,6 @@ const updateFTP = async (updatedFilepath, submitter) => { ...@@ -855,6 +854,6 @@ const updateFTP = async (updatedFilepath, submitter) => {
processedFilename, processedFilename,
) )
} catch (err) { } catch (err) {
logger.error('Error with updating FTP') logger.error('Error with updating FTP', err)
} }
} }
...@@ -134,8 +134,9 @@ module.exports.renameBulkFtpPackage = async function renameBulkFtpPackage( ...@@ -134,8 +134,9 @@ module.exports.renameBulkFtpPackage = async function renameBulkFtpPackage(
close(ftp) close(ftp)
reject(err) reject(err)
} }
// get array of tar.gz files only
const ftpPackageName = await checkBulkFtpPackage(processedFilename) const ftpPackageName = await checkBulkFtpPackage(processedFilename)
// get array of tar.gz files only
const ftpFile = list.filter( const ftpFile = list.filter(
file => file.name === ftpPackageName && file.type === '-', file => file.name === ftpPackageName && file.type === '-',
)[0] )[0]
...@@ -181,7 +182,7 @@ module.exports.renameBulkFtpPackage = async function renameBulkFtpPackage( ...@@ -181,7 +182,7 @@ module.exports.renameBulkFtpPackage = async function renameBulkFtpPackage(
function checkBulkFtpPackage(packageName) { function checkBulkFtpPackage(packageName) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const file_ext = new RegExp( const file_ext = new RegExp(
/((\.start\.loaded\.mid-EMS\d+)|(\.start\.ERROR))\.\d{4}-\d{2}-\d{2}_\d{2}:\d{2}:\d{2}$/i, /((\.start\.loaded\.mid-EMS\d+)|(\.start\.ERROR)|(\.ERROR))\.\d{4}-\d{2}-\d{2}_\d{2}:\d{2}:\d{2}$/i,
) )
if (file_ext.test(packageName)) resolve(packageName.split(file_ext)[0]) if (file_ext.test(packageName)) resolve(packageName.split(file_ext)[0])
else else
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment