diff --git a/lib/chunks.js b/lib/chunks.js index 19c555460ab..5fa79a0bd54 100644 --- a/lib/chunks.js +++ b/lib/chunks.js @@ -701,7 +701,15 @@ const ensureChunk = async (courseId, chunk) => { }); // Finally, link targetPath -> relativeUnpackPath - await fs.ensureSymlink(relativeUnpackPath, targetPath); + // Note that ensureSymlink() won't overwrite an existing targetPath + // See: + // https://github.com/jprichardson/node-fs-extra/pull/869 + // https://github.com/jprichardson/node-fs-extra/issues/786 + // https://github.com/jprichardson/node-fs-extra/pull/826 + // As a work-around, we symlink a temporary name and move it over targetPath + const tmpPath = `${targetPath}-${chunk.uuid}`; + await fs.ensureSymlink(relativeUnpackPath, tmpPath); + await fs.rename(tmpPath, targetPath); }; /** @type {Map} */