ENOENT,没有这样的文件或目录,但文件存在 [英] ENOENT, no such file or directory but file exists

查看:476
本文介绍了ENOENT,没有这样的文件或目录,但文件存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Intel Edison上的NodeJ进行构建.我正在使用插件: https://github.com/blueimp/jQuery-File-Up和NodeJS服务器端部分.

I'm trying to build something using NodeJs on Intel Edison. I am using the plugin: https://github.com/blueimp/jQuery-File-Upload and the NodeJS Server side part.

但是,我不断得到

fs.js:543
  return binding.rename(pathModule._makeLong(oldPath),
                 ^
Error: ENOENT, no such file or directory '/home/root/db/node_modules/blueimp-file-upload-node/tmp/8fa2946958c04ad8cb6def7b1e9dab01'
    at Object.fs.renameSync (fs.js:543:18)
    at IncomingForm.<anonymous> (/home/root/db/node_modules/blueimp-file-upload-node/server.js:248:16)
    at IncomingForm.EventEmitter.emit (events.js:98:17)
    at /home/root/db/node_modules/blueimp-file-upload-node/node_modules/formidable/lib/incoming_form.js:228:12
    at WriteStream.<anonymous> (/home/root/db/node_modules/blueimp-file-upload-node/node_modules/formidable/lib/file.js:70:5)
    at WriteStream.g (events.js:180:16)
    at WriteStream.EventEmitter.emit (events.js:117:20)
    at finishMaybe (_stream_writable.js:360:12)
    at afterWrite (_stream_writable.js:280:5)
    at onwrite (_stream_writable.js:270:7)

每当我尝试上传内容时,问题是文件/home/root/db/node_modules/blueimp-file-upload-node/tmp/8fa2946958c04ad8cb6def7b1e9dab01确实存在,并且我猜测我也拥有该文件夹中的权限.

Whenever I try to upload something.The problem is that the file /home/root/db/node_modules/blueimp-file-upload-node/tmp/8fa2946958c04ad8cb6def7b1e9dab01 does indeed exist and I guess that I also have the permissions right in the folder.

我尝试了几件事,但是我真的被困在这里,我不明白如何解决这个问题.

I tried several things, but I am really stuck here, I cannot understand how can I get around this.

推荐答案

出现错误后,文件的名称是旧名称还是新名称? (我曾经遇到过两个线程被意外启动,而第二个发现文件已经消失的情况).目标目录是否存在?有错别字吗?

After the error, is the file there by the old name or the new name? (I've had cases where two threads were inadvertenly started, and the second found the file already gone). Does the target directory exist? Any typos?

这是Linux手册页关于重命名的内容:

Here's what the linux manpage says about rename:

ENOENT由oldpath命名的链接不存在;该链接不存在.或newpath中的目录组件 不存在;或者,oldpath或newpath是一个空字符串.

ENOENT The link named by oldpath does not exist; or, a directory component in newpath does not exist; or, oldpath or newpath is an empty string.

这是一个nodejs错误,它报告实际上是问题的目标目录时缺少源文件.要从命令行重现:

this is a nodejs bug, it reports that the source file is missing when it's actually the destination directory that's the problem. To reproduce from the command line:

% touch /tmp/file.txt
% node -p 'fs = require("fs"); fs.renameSync("/tmp/file.txt", "/nonesuch/file.txt");'

它打印:

Error: ENOENT, no such file or directory '/tmp/file.txt'
    at Object.fs.renameSync (fs.js:548:18)
    at [eval]:1:24
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:456:26)
    at evalScript (node.js:536:25)
    at startup (node.js:80:7)
    at node.js:906:3

这是包装renameSync()来解决此问题的一种可能方法(未经测试!)

here's a possible way to wrapper renameSync() to fix this (untested!)

var _origRename = fs.renameSync;
fs.renameSync = function(from, to) {
    try { _origRename(from, to) }
    catch (err) {
        if (err.stack.indexOf('ENOENT') < 0) throw err;
        try { fs.statSync(from) } catch (err2) { throw err }
        throw new Error("ENOENT, no such file or directory '" + to "'");
    }
}

这篇关于ENOENT,没有这样的文件或目录,但文件存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆