1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Tools: Trying to fix encodeAssets EEXIST error

This commit is contained in:
Laurent Cozic 2022-10-11 11:43:22 +01:00
parent 13c1ae3d39
commit 2c49270f38
2 changed files with 23 additions and 3 deletions

View File

@ -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`;

View File

@ -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);
};