Changes
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2022-09-07 10:26:32 +02:00
parent 7264595646
commit aba1696ad7
1 changed files with 8 additions and 8 deletions

View File

@ -56,8 +56,6 @@ module.exports = Self => {
for (const table of tables) {
const fileName = table.file;
console.debug(`Downloading file ${fileName}...`);
remoteFile = `codes/${fileName}.ZIP`;
tempDir = `${tempPath}/${fileName}`;
tempFile = `${tempPath}/${fileName}.zip`;
@ -66,14 +64,14 @@ module.exports = Self => {
await fs.readFile(tempFile);
} catch (error) {
if (error.code === 'ENOENT') {
console.debug(`Downloading file ${fileName}...`);
const downloadOutput = await downloadFile(remoteFile, tempFile);
if (downloadOutput.error)
continue;
}
}
console.debug(`Extracting file ${fileName}...`);
await extractFile(tempFile, tempDir);
await extractFile(fileName, tempFile, tempDir);
console.debug(`Updating table ${table.toTable}...`);
await dumpData(tempDir, table);
@ -90,6 +88,7 @@ module.exports = Self => {
// Clean files
try {
console.debug(`Cleaning files...`);
await fs.remove(tempPath);
} catch (error) {
if (error.code !== 'ENOENT')
@ -128,7 +127,7 @@ module.exports = Self => {
ftpClient.exec((err, response) => {
if (err || response.error) {
console.debug(`Error downloading checksum file... ${response.error}`);
reject(err);
return reject(err);
}
resolve(response);
@ -159,9 +158,9 @@ module.exports = Self => {
return new Promise((resolve, reject) => {
ftpClient.exec((err, response) => {
if (response.error) {
if (err || response.error) {
console.debug(`Error downloading file... ${response.error}`);
reject(err);
return reject(err);
}
resolve(response);
@ -169,11 +168,12 @@ module.exports = Self => {
});
}
async function extractFile(tempFile, tempDir) {
async function extractFile(fileName, tempFile, tempDir) {
const JSZip = require('jszip');
try {
await fs.mkdir(tempDir);
console.debug(`Extracting file ${fileName}...`);
} catch (error) {
if (error.code !== 'EEXIST')
throw e;