ForgeRock / fr-config-manager

ForgeRock config manager
MIT License
6 stars 7 forks source link

Bug in update-raw.js #145

Closed nigelelliott75 closed 2 months ago

nigelelliott75 commented 3 months ago

There is a bug in https://github.com/ForgeRock/fr-config-manager/blob/main/packages/fr-config-push/src/scripts/update-raw.js where the code is navigating the folder structure multiple times.

The code in question is shown below the fs.readdirSync has recursive set to true which means it will go down through the folder structure, however the files map has code which will call itself if it sees a folder and so also navigating through the filesystem as well and so duplicating the effort and in some circumstances causes undefined errors in the response.

`async function listFiles(dir) { const files = fs.readdirSync(dir, { withFileTypes: true, recursive: true });

const filesAndDirs = await Promise.all( files.map(async (file) => { const filePath = path.join(dir, file.name); if (file.isDirectory()) { return listFiles(filePath); // Recursively list files } else { return filePath; // Return file path } }) );

return filesAndDirs.flat(); } `

I fixed the issue locally by switching the true to false for recursive, i.e.

`async function listFiles(dir) { const files = fs.readdirSync(dir, { withFileTypes: true, recursive: false });

const filesAndDirs = await Promise.all( files.map(async (file) => { const filePath = path.join(dir, file.name); if (file.isDirectory()) { return listFiles(filePath); // Recursively list files } else { return filePath; // Return file path } }) );

return filesAndDirs.flat(); } `

christian-brindley commented 2 months ago

Fixed as suggested. Also fixed issue with creation of raw config which requires If-None-Match header.