【发布时间】:2019-05-15 22:57:49
【问题描述】:
我正在为Atom editor 写包。
在 Mac 上运行我的包中使用 fs-plus makeTree 方法时遇到的 persmission denied 错误,谁能提供帮助?在 Windows 上没有错误。
我使用 fs-plus,它与 Atom 在其 tree-view 包中使用的模块相同(并且树视图在 Mac 上工作)。
UPD:添加屏幕截图和一些代码:
图片上显示的新文件夹选项是使用相同的模块 - fs-plus 实现的,它适用于 Mac。我只使用相同的模块和相同的方法(fs-plus.makeTree)来创建目录,但我的实现失败了Permission denied error。
我的代码:
import util from 'util';
import { sep } from 'path';
import fs from 'fs-plus';
const makeTreeAsync = util.promisify(fs.makeTree);
createTutorial(data) {
const { initialPath } = this;
const { fileName } = data;
const filePath = `${initialPath}${sep}${fileName}${sep}${fileName}.md`;
return makeTreeAsync(fileName)
.then(() => writeFileAsync(filePath, this.getContent(data)))
.then(() => filePath);
},
来自树视图包的代码:
path = require 'path'
fs = require 'fs-plus'
onConfirm: (newPath) ->
newPath = newPath.replace(/\s+$/, '') # Remove trailing whitespace
endsWithDirectorySeparator = newPath[newPath.length - 1] is path.sep
unless path.isAbsolute(newPath)
// some path preprocessing
return unless newPath
try
if fs.existsSync(newPath)
@showError("'#{newPath}' already exists.")
else if @isCreatingFile
// some code, we are not interested in as we 're creating directory
else
fs.makeTreeSync(newPath)
@emitter.emit('did-create-directory', newPath)
@cancel()
catch error
@showError("#{error.message}.")
重要提示:我的包是手动安装的(复制到~/<username>/.atom/packages)然后运行npm i
【问题讨论】:
-
请发布产生问题的相关代码。
-
谢谢,我已经更新了
标签: node.js electron atom-editor