Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: force clean #41

Merged
merged 5 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions packages/cli/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ exports.install = async options => {
const mountedInfo = currentMountInfo.find(item => item.mountPoint === nodeModulesDir);

if (mountedInfo) {
console.log(`[rapid] ${nodeModulesDir} already mounted, try to clean`);
console.time(`[rapid] ${nodeModulesDir} already mounted, try to clean`);
await exports.clean(path.join(options.cwd, pkgPath), true);
console.timeEnd(`[rapid] ${nodeModulesDir} already mounted, try to clean`);
}

await fs.mkdir(baseDir, { recursive: true });
Expand Down Expand Up @@ -67,20 +68,20 @@ exports.install = async options => {
console.timeEnd('[rapid] run lifecycle scripts');
};

exports.clean = async function clean(cwd) {
const mode = await nydusd.getNydusInstallMode(cwd);
if (!mode) {
console.log(`[rapid] invalid mode ${mode} ignore`);
exports.clean = async function clean(cwd, force = false) {
const listInfo = await util.listMountInfo();
if (!listInfo.length) {
console.log('[rapid] no mount info found.');
return;
}
const { pkg } = await util.readPkgJSON(cwd);
await nydusd.endNydusFs(mode, cwd, pkg);
await nydusd.endNydusFs('FUSE', cwd, pkg, force);
elrrrrrrr marked this conversation as resolved.
Show resolved Hide resolved
};

exports.list = async () => {
const running = await nydusdApi.isDaemonRunning();
if (!running) {
console.error('[rapid] nydusd is not running, please run `rapid install` first.');
return;
console.warn('[rapid] nydusd is not running, please run `rapid install` first.');
}
const listInfo = await util.listMountInfo();
if (!listInfo.length) {
Expand Down
24 changes: 11 additions & 13 deletions packages/cli/lib/nydusd/fuse_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,21 @@ ${nodeModulesDir}`;
}
}

async function endNydusFs(cwd, pkg) {
async function endNydusFs(cwd, pkg, force = false) {
const allPkgs = await getAllPkgPaths(cwd, pkg);
const umountCmd = force ? 'umount -f' : 'umount';
for (const pkgPath of allPkgs) {
const {
dirname,
overlay,
baseDir,
nodeModulesDir,
} = await getWorkdir(cwd, pkgPath);
const { dirname, overlay, baseDir, nodeModulesDir } = await getWorkdir(
cwd,
pkgPath
);
if (os.type() === 'Darwin') {
console.log(`[rapid] umount ${nodeModulesDir}`);
await execa.command(`umount ${nodeModulesDir}`);
// hdiutil detach
await execa.command(`hdiutil detach ${overlay}`);
killagu marked this conversation as resolved.
Show resolved Hide resolved
console.log(`[rapid] ${umountCmd} ${nodeModulesDir}`);
await execa.command(`${umountCmd} ${nodeModulesDir}`);
await execa.command(`${umountCmd} ${overlay}`);
} else {
await execa.command(wrapSudo(`umount ${nodeModulesDir}`));
await execa.command(wrapSudo(`umount ${overlay}`));
await execa.command(wrapSudo(`${umountCmd} ${nodeModulesDir}`));
await execa.command(wrapSudo(`${umountCmd} ${overlay}`));
}
await nydusdApi.umount(`/${dirname}`);
// 清除 nydus 相关目录
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/lib/nydusd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ exports.startNydusFs = async function(mode, cwd, pkg) {
await impl.start(cwd, pkg);
};

exports.endNydusFs = async function(mode, cwd, pkg) {
exports.endNydusFs = async function(mode, cwd, pkg, force) {
if (!mode || mode === NYDUS_TYPE.NATIVE) {
console.log('[rapid] nydusd is not running, skip clean');
return;
}
const impl = fsImplMap[mode];
assert(impl, `can not find fs impl for mode: ${mode}`);
await impl.end(cwd, pkg);
await impl.end(cwd, pkg, force);
};

exports.getNydusMode = async function(cwd) {
Expand Down
Loading