Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "EXDEV: cross-device link not permitted" error mean?

Tags:

node.js

libuv

What does this error actually mean? What is a "cross-device link"?

It is mentioned on this libuv page but it doesn't give any details beyond "cross-device link not permitted".

like image 889
callum Avatar asked Apr 04 '17 11:04

callum


4 Answers

It sounds like you're trying to rename a file across "device" (partition) boundaries.

Say that /tmp is a different partition than /. That means that you're not allowed to do this:

fs.rename('/tmp/myfile.txt', '/myfile.txt', ...)

(the same applies to fs.renameSync() as well, obviously)

If you want to do that, you need to first copy the file to its new location, and subsequently remove the old file. There are modules, like mv, that can help you with that.

like image 99
robertklep Avatar answered Nov 05 '22 04:11

robertklep


It is used for EXDEV on Linux:

See man rename manpage:

  • http://man7.org/linux/man-pages/man2/rename.2.html

EXDEV oldpath and newpath are not on the same mounted filesystem. (Linux permits a filesystem to be mounted at multiple points, but rename() does not work across different mount points, even if the same filesystem is mounted on both.)

This error is also used when there is ERROR_NOT_SAME_DEVICE on Windows, see:

  • https://github.com/libuv/libuv/blob/v1.x/src/win/error.c#L166

For more info see:

  • http://errorco.de/win32/winerror-h/error_not_same_device/0x80070011/

winerror.h 0x80070011 #define ERROR_NOT_SAME_DEVICE The system cannot move the file to a different disk drive.

like image 28
rsp Avatar answered Nov 05 '22 05:11

rsp


I guess you are trying to copy a file from /temp folder since the form. I solved it coping, not renaming

        fs.copyFile(oldpath, newpath, function (err) {
            if (err) throw err;
            res.write('File uploaded and moved!');
            res.end();
        });
like image 11
Mauricio Romero Avatar answered Nov 05 '22 03:11

Mauricio Romero


Just for they guys who are using Linux this happens when your old path i.e. /tmp and new path are on different partitions or disks.

like image 3
Suleman Hasib Avatar answered Nov 05 '22 04:11

Suleman Hasib