"EXDEV: cross-device link not permitted" 错误是什么意思?

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

这个错误到底是什么意思?什么是 "cross-device link"?

this libuv page 中提到了它,但它没有提供 "cross-device link not permitted" 以外的任何细节。

听起来您正在尝试跨 "device"(分区)边界重命名文件。

假设 /tmp/ 是不同的分区。这意味着您不能这样做:

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

(同样适用于fs.renameSync(),显然)

如果要这样做,您需要先将文件复制到新位置,然后删除旧文件。有一些模块,例如 mv,可以帮助您。

用于 Linux 上的 EXDEV:

参见 man rename 联机帮助页:

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.)

当Windows上有ERROR_NOT_SAME_DEVICE时也会出现这个错误,见:

有关详细信息,请参阅:

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

仅供使用 Linux 的人使用,当您的旧路径(即 /tmp 和新路径位于不同的分区或磁盘上时,就会发生这种情况。

我猜您正试图从 /temp 文件夹中复制表格后的文件。我解决了它应对,而不是重命名

        fs.copyFile(oldpath, newpath, function (err) {
            if (err) throw err;
            res.write('File uploaded and moved!');
            res.end();
        });