mirror of
https://github.com/whyour/qinglong.git
synced 2025-11-23 00:49:19 +08:00
修复 homedir 权限
This commit is contained in:
parent
8f23c61fee
commit
72d4c8bfd4
|
|
@ -4,6 +4,8 @@ import os from 'os';
|
||||||
import chokidar from 'chokidar';
|
import chokidar from 'chokidar';
|
||||||
import config from '../config/index';
|
import config from '../config/index';
|
||||||
import { promiseExec } from '../config/util';
|
import { promiseExec } from '../config/util';
|
||||||
|
import { W_OK } from 'constants';
|
||||||
|
import Logger from './logger';
|
||||||
|
|
||||||
async function linkToNodeModule(src: string, dst?: string) {
|
async function linkToNodeModule(src: string, dst?: string) {
|
||||||
const target = path.join(config.rootPath, 'node_modules', dst || src);
|
const target = path.join(config.rootPath, 'node_modules', dst || src);
|
||||||
|
|
@ -17,19 +19,29 @@ async function linkToNodeModule(src: string, dst?: string) {
|
||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function ensureDirWritable(dir: string) {
|
||||||
|
try {
|
||||||
|
await fs.access(dir, W_OK);
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function linkCommand() {
|
async function linkCommand() {
|
||||||
const homeDir = os.homedir();
|
const homeDir = os.homedir();
|
||||||
const userBinDir = path.join(homeDir, 'bin');
|
let userBinDir = path.join(homeDir, 'bin');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fs.mkdir(userBinDir, { recursive: true });
|
if (!(await ensureDirWritable(homeDir))) {
|
||||||
} catch (error) {
|
|
||||||
const commandPath = await promiseExec('which node');
|
const commandPath = await promiseExec('which node');
|
||||||
const commandDir = path.dirname(commandPath);
|
userBinDir = path.dirname(commandPath);
|
||||||
return await linkCommandToDir(commandDir);
|
|
||||||
}
|
}
|
||||||
|
await fs.mkdir(userBinDir, { recursive: true });
|
||||||
await linkCommandToDir(userBinDir);
|
await linkCommandToDir(userBinDir);
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error('Linking command failed:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function linkCommandToDir(commandDir: string) {
|
async function linkCommandToDir(commandDir: string) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user