From 2c13f8caa25119cb6b2acc39ca212598130b84e4 Mon Sep 17 00:00:00 2001 From: akitaSummer Date: Tue, 5 Mar 2024 12:06:17 +0800 Subject: [PATCH] feat: update mac already clean --- packages/cli/lib/deamon.js | 26 ++++++++++++++------------ packages/cli/lib/index.js | 15 +++++++++++++-- packages/cli/lib/nydusd/fuse_mode.js | 4 +--- packages/cli/package.json | 3 ++- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/packages/cli/lib/deamon.js b/packages/cli/lib/deamon.js index 97e3df5..3854c2d 100644 --- a/packages/cli/lib/deamon.js +++ b/packages/cli/lib/deamon.js @@ -207,21 +207,23 @@ root: }; const initDeamon = async () => { - const isRunning = await checkDeamonAlive(); - if (isRunning) { - console.info('[rapid] rapid daemon is running already.'); - return; - } - await fs.mkdir(deamonDir, { recursive: true }); - - await fs.mkdir(nydusdMnt, { recursive: true }); - try { - const rapidVersion = require(path.join(__dirname, '../package.json')).version; - const deamonVersion = require(path.join(deamonDir, 'package.json')).version; + const rapidVersion = require(path.join(__dirname, '../package.json')).deamonVersion; + const deamonVersion = require(path.join(deamonDir, './package.json')).deamonVersion; + console.log(rapidVersion, deamonVersion); if (rapidVersion !== deamonVersion) { - throw Error('[rapid] rapid and deamon version not match'); + const err = '[rapid] rapid and deamon version not match'; + console.info(err); + throw Error(err); + } + const isRunning = await checkDeamonAlive(); + if (isRunning) { + console.info('[rapid] rapid daemon is running already.'); + return; } + await fs.mkdir(deamonDir, { recursive: true }); + + await fs.mkdir(nydusdMnt, { recursive: true }); await fs.stat(destinationFilePath); } catch (e) { await registerDeamon(); diff --git a/packages/cli/lib/index.js b/packages/cli/lib/index.js index 30b6c0d..250a694 100644 --- a/packages/cli/lib/index.js +++ b/packages/cli/lib/index.js @@ -35,12 +35,23 @@ exports.install = async options => { const { baseDir, tarIndex, nodeModulesDir } = await util.getWorkdir(options.cwd, pkgPath); const mountedInfo = currentMountInfo.find(item => item.mountPoint === nodeModulesDir); + let isMounted = false; + + if (os.type() === 'Darwin') { + try { + await fs.stat(nodeModulesDir); + isMounted = true; + } catch (e) { + console.log(e); + } + await fs.rm(nodeModulesDir, { recursive: true, force: true }); + } - if (mountedInfo) { + if (mountedInfo || isMounted) { console.time(`[rapid] ${nodeModulesDir} already mounted, try to clean`); await exports.clean({ nydusMode: options.nydusMode, - cwd: mountedInfo.mountPoint, + cwd: options.cwd, pkg: options.pkg, force: true, daemon: options.daemon, diff --git a/packages/cli/lib/nydusd/fuse_mode.js b/packages/cli/lib/nydusd/fuse_mode.js index dfc6076..3aa79c5 100644 --- a/packages/cli/lib/nydusd/fuse_mode.js +++ b/packages/cli/lib/nydusd/fuse_mode.js @@ -95,9 +95,7 @@ async function mountNydus(cwd, pkg, config) { // 需要串行 mount,并发创建时 nydusd 会出现问题 for (const pkgPath of allPkgs) { const { dirname, bootstrap, nodeModulesDir } = await getWorkdir(cwd, pkgPath); - if (os.type() === 'Darwin') { - await fs.rm(nodeModulesDir, { recursive: true, force: true }); - } + const nydusdConfig = await nydusdApi.mount(`/${dirname}`, cwd, bootstrap); mounts.push({ mountpoint: `${dirname}`, diff --git a/packages/cli/package.json b/packages/cli/package.json index f86c74d..27a7556 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -49,5 +49,6 @@ "rapid", "npm" ], - "author": "gemwuu (https://github.com/gemwuu)" + "author": "gemwuu (https://github.com/gemwuu)", + "deamonVersion": "0.0.1" }