1

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.

However, I keep getting

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)

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.

0andriy
  • 4,183
  • 1
  • 24
  • 37
J D
  • 1,768
  • 2
  • 18
  • 20

1 Answers1

0

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?

Here's what the linux manpage says about rename:

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.

Edit: 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");'

it prints:

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

Edit: 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 "'");
    }
}
Andras
  • 2,995
  • 11
  • 17
  • File is there by the old name and the target directory doesn't exist (but that should not be a problem since it's not reading in the first place). No typos. – J D Nov 30 '14 at 14:35
  • aha! it's reproducible from the command line, see the edit above -- node reports that the source is not found even when the problem is with the destination – Andras Nov 30 '14 at 18:40
  • Yups. :( Any idea how to get around it? – J D Nov 30 '14 at 19:14
  • should be easy to wrapper the rename / renameSync commands to try/catch the rename and test the source file on error. Easy, but a pain. The can be wrappered and replaced in fact, so your whole app would benefit from the fix. – Andras Nov 30 '14 at 19:41
  • see the edit above for a simple wrapper to renameSync – Andras Nov 30 '14 at 19:48
  • This was driving me crazy! I didn't think to check the destination path. – EasyCo Feb 14 '15 at 00:30