7

Renaming a file on Debian Wheezy does not work using fs.rename or fs.renameSync.

This only happens in files moved from /tmp/ to another location.

The reported error is: EXDEV, cross-device link not permitted.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Thomaschaaf
  • 17,847
  • 32
  • 94
  • 128
  • You can see that. I think it useful for u [here][1] [1]: http://stackoverflow.com/questions/4568689/how-do-i-move-file-a-to-a-different-partition-in-node-js – SaliproPham Oct 15 '12 at 08:32
  • Possible duplicate of [How do I move file a to a different partition or device in Node.js?](https://stackoverflow.com/questions/4568689/how-do-i-move-file-a-to-a-different-partition-or-device-in-node-js) – bugwheels94 Jul 19 '17 at 10:34

2 Answers2

2

This is another solution that works for me:

var fs = require("fs"),
util = require('util');
...
//fs.renameSync(files.upload.path, "/tmp/test.png");

var readStream = fs.createReadStream(files.upload.path)
var writeStream = fs.createWriteStream("/tmp/test.png");

util.pump(readStream, writeStream, function() {
    fs.unlinkSync(files.upload.path);
});
Pang
  • 9,564
  • 146
  • 81
  • 122
Bruce Yo
  • 152
  • 1
  • 12
0

Debian Wheezy uses tmpfs for the /tmp folder by default.

This can be turned off by modifing /etc/default/rcS.

RAMTMP=yes

has to be set to

RAMTMP=no
Thomaschaaf
  • 17,847
  • 32
  • 94
  • 128
  • 3
    The problem is that Node fs.renameSync cannot do cross-device renames, not that some particular machine has tmp on different device. Don't turn off RAMTMP just because this. (Also on current Debian Jessie RAMTMP doesn't work, /tmp tmpfs is configured via systemd.) Use some smarter rename, for example the module __mv__: http://stackoverflow.com/a/29287813/196206 – Messa Aug 18 '15 at 11:38