运行 fs-plus 模块时权限被拒绝

Permission denied when running fs-plus module

我正在为 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

经过一段时间的调试,我有一个解决方案。我尝试使用本机 fs.mkdir 但没有成功,但在我将模式添加为第二个参数后 - 它起作用了。

const _0777 = parseInt('0777', 8);
const mode = _0777 & (~process.umask());

fs.mkdir(<folderPath>, mode, () => {});

希望,这会对某人有所帮助。