diff --git a/packages/app-mobile/tools/encodeAssets.js b/packages/app-mobile/tools/encodeAssets.js index d67389d1e..3e37465a2 100644 --- a/packages/app-mobile/tools/encodeAssets.js +++ b/packages/app-mobile/tools/encodeAssets.js @@ -25,7 +25,8 @@ async function encodeFile(sourcePath, destPath) { const hash = md5(buffer.toString('base64')); const js = `module.exports = \`${buffer.toString('base64')}\`;`; const outputPath = `${outputDir}/${destPath}.base64.js`; - await fs.mkdirp(utils.dirname(outputPath)); + console.info(`Encoding "${sourcePath}" => "${outputPath}"`); + await utils.mkdirp(utils.dirname(outputPath)); await fs.writeFile(outputPath, js); const ext = utils.fileExtension(sourcePath).toLowerCase(); @@ -44,7 +45,7 @@ async function encodeFile(sourcePath, destPath) { async function main() { await fs.remove(outputDir); - await fs.mkdirp(outputDir); + await utils.mkdirp(outputDir); const encodedFiles = []; const sourceAssetDir = `${rootDir}/../renderer/assets`; diff --git a/packages/tools/gulp/utils.js b/packages/tools/gulp/utils.js index 94312b451..18c244d58 100644 --- a/packages/tools/gulp/utils.js +++ b/packages/tools/gulp/utils.js @@ -134,14 +134,33 @@ utils.copyDir = async function(src, dest, options) { } }; +// Occasionally, fs.mkdirp throws a "EEXIST" error if the directory already +// exists, while it should actually ignore the error. So we have this wrapper +// that actually handle the error. It means in general this method should be +// preferred to avoid random failures on CI or when building the app. +// +// https://github.com/laurent22/joplin/issues/6935#issuecomment-1274404470 utils.mkdir = async function(dir) { if (utils.isWindows()) { return utils.execCommand(`if not exist "${utils.toSystemSlashes(dir)}" mkdir "${utils.toSystemSlashes(dir)}"`); } else { - return fs.mkdirp(dir); + try { + // Can't return right away, or the exception won't be caught + const result = await fs.mkdirp(dir); + return result; + } catch (error) { + // Shouldn't happen but sometimes does. So we ignore the error in + // this case. + if (error.code === 'EEXIST') return; + throw error; + } } }; +utils.mkdirp = async function(dir) { + return utils.mkdir(dir); +}; + utils.copyFile = async function(src, dest) { await fs.copy(src, dest); };