Skip to content

Commit

Permalink
use remove symlink function
Browse files Browse the repository at this point in the history
  • Loading branch information
KenCorma committed Oct 27, 2024
1 parent 7d149ca commit 5623751
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions scripts/todesktop/afterPack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand All @@ -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')
Expand Down

0 comments on commit 5623751

Please sign in to comment.