【问题标题】:Permission denied when running fs-plus module运行 fs-plus 模块时权限被拒绝
【发布时间】: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


【解决方案1】:

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

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

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

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-13
  • 2014-11-15
  • 2017-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多