From 40239d2e355da883be47158d8a53ad34cf1bf63b Mon Sep 17 00:00:00 2001 From: Matthew West Date: Tue, 23 Feb 2021 08:50:13 -0600 Subject: [PATCH] Fix chunk symlinks to ensure overwriting old links --- lib/chunks.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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} */