我在我的一个项目中使用gulp。从OS(Arch Linux)运行gulp watch
时
fs.js:921
return binding.readdir(pathModule.toNamespacedPath(path), options.encoding);
^
Error: EACCES: permission denied, scandir '/tmp/systemd-private-c33e4391b18f4b24af3055190fb15730-systemd-hostnamed.service-zrxyaX/'
at Object.fs.readdirSync (fs.js:921:18)
at Gaze._addToWatched (/home/majmun/code/wp/wp-content/plugins/project/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:274:22)
at Gaze._internalAdd (/home/majmun/code/wp/wp-content/plugins/project/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:191:10)
at /home/majmun/code/wp/wp-content/plugins/project/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:400:16
at Array.forEach (<anonymous>)
at /home/majmun/code/wp/wp-content/plugins/project/node_modules/glob-watcher/node_modules/gaze/lib/gaze.js:396:12
at FSReqWrap.oncomplete (fs.js:153:20)
我从主机操作系统运行gulp而不是虚拟机,因为它更快。
我理解问题是gulp正在主机操作系统的/tmp
文件夹中执行某些操作,而某些文件具有root权限。
如果我运行sudo chown -R majmun:users /tmp
,之后会出现具有root权限的新文件,这会破坏gulp。
为什么gulp watch需要/tmp
个文件夹。
有人解决了这个问题吗?
这是gulp watch任务的代码 // gulp watch
Gulp.task('watch', ['dev'], function() {
console.log('Initializing assets watcher:')
let stream = new Stream();
let filter = '*.{css,scss,sass,less,js,png,jpg,jpeg,svg}';
let tmp = Tmp.fileSync();
let glob = [
path.src.assets + '**/' + filter,
path.src.elements + '**/' + filter,
path.src.properties + '**/' + filter,
];
for (let i = 0; i < glob.length; i++) {
console.log('- ' + glob[i]);
}
let watcher = Gulp.watch(glob, ['dev']);
watcher.add(tmp.name);
process.on('SIGINT', function() {
stream.emit('end');
process.exit(0);
});
KeyPress(process.stdin);
process.stdin.on('keypress', function(char, key) {
if (key && key.ctrl && key.name == 'c') {
process.emit('SIGINT');
}
else if (key && key.ctrl && key.name == 'r') {
Fs.utimes(tmp.name, new Date(), new Date(), function() {});
}
});
process.stdin.setRawMode(true);
process.stdin.resume();
console.log('Watcher up and running, Ctrl+R to refresh, Ctrl+C to exit.');
return stream;
});
答案 0 :(得分:0)
我通过使用tmp
库添加一些选项来解决此问题。我指定了临时文件夹的位置及其权限,而不是默认选项。
所以代替这个:
let tmp = Tmp.fileSync();
我这样做了:
let tmp = Tmp.fileSync({
// Use settings from .env if defined
dir: process.env.MY_TMP_DIR || ''
mode: process.env.MY_TMP_MODE || '',
prefix: process.env.MY_TMP_PREFIX || '',
});