From 56237515a61029565146687fe9c03becdec7df95 Mon Sep 17 00:00:00 2001 From: Kendal Cormany Date: Sat, 26 Oct 2024 20:29:10 -0700 Subject: [PATCH] use remove symlink function --- scripts/todesktop/afterPack.js | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/scripts/todesktop/afterPack.js b/scripts/todesktop/afterPack.js index 7e22396b..78d0523e 100644 --- a/scripts/todesktop/afterPack.js +++ b/scripts/todesktop/afterPack.js @@ -13,6 +13,66 @@ module.exports = async ({ appOutDir, packager,outDir }) => { * arch - number - the architecture of the app. ia32 = 0, x64 = 1, armv7l = 2, arm64 = 3, universal = 4. */ + async function removeInvalidSymlinks({ + // string + appPath, + }) { + const invalidSymlinksInManyLines = await new Promise((resolve, reject) => { + exec(`find ${appPath}/Contents -type l ! -exec test -e {} \\; -print`, (error, stdout, stderr) => { + console.log(`command: find ${appPath}/Contents -type l ! -exec test -e {} \\; -print`) + if (error) { + console.error(`error: ${error.message}`); + return reject(error); + } + if (stderr) { + console.log(`stderr: ${stderr}`); + return reject(stderr); + } + console.log(`stdout: ${stdout}`); + resolve(stdout); + }) + }); + + console.log("======invalidSymlinksInManyLines======") + console.log(invalidSymlinksInManyLines) + console.log("===========================") + + const invalidSymlinksInArray = invalidSymlinksInManyLines.split("\n") + .map((invalidSymlink) => invalidSymlink.trim()) + .filter((maybeEmptyPath) => maybeEmptyPath !== ''); + + console.log("======invalidSymlinksInArray======") + console.log(invalidSymlinksInArray) + console.log("===========================") + + const waitUntilAllInvalidSymlinksRemoved = invalidSymlinksInArray.map((invalidSymlink) => { + return new Promise((resolve) => { + exec(`rm ${invalidSymlink}`, (error, stdout, stderr) => { + console.log(`command: rm ${invalidSymlink}`) + + if (error) { + console.error(`error: ${error.message}`); + return reject(error); + } + if (stderr) { + console.log(`stderr: ${stderr}`); + return reject(stderr); + } + console.log(`stdout: ${stdout}`); + resolve(stdout); + }) + }) + }) + + try { + await Promise.all(waitUntilAllInvalidSymlinksRemoved); + } catch (e) { + console.log(`error happened while removing all invalid symlinks. message: ${e.message}`); + } + + return; + } + if (os.platform() === "darwin") { const appName = packager.appInfo.productFilename; const appPath = path.join(`${appOutDir}`, `${appName}.app`); @@ -21,6 +81,7 @@ module.exports = async ({ appOutDir, packager,outDir }) => { const resourcePath = path.join(appPath,"Contents","Resources"); await fs.rm(path.join(assetPath,"ComfyUI",".git"),{recursive:true,force:true}); await fs.cp(assetPath, resourcePath, {recursive: true}); + await removeInvalidSymlinks(appPath); } if (os.platform() === 'win32')