【发布时间】:2022-06-30 10:33:58
【问题描述】:
我尝试在 linux 和 windows 中运行以下代码:
const fs = require("fs/promises")
const {
constants,
existsSync
} = require("fs")
async function copy() {
try {
await fs.writeFile("demo.txt", "Hello World")
await fs.copyFile("demo.txt", "copy.txt", constants.COPYFILE_FICLONE_FORCE)
} finally {
fs.rm("demo.txt")
if (existsSync("copy.txt")) fs.rm("copy.txt")
}
}
copy().catch(console.error)
都失败了,错误信息:
Linux:
[Error: ENOTSUP: operation not supported on socket, copyfile 'demo.txt' -> 'copy.txt'] {
errno: -95,
code: 'ENOTSUP',
syscall: 'copyfile',
path: 'demo.txt',
dest: 'copy.txt'
}
窗口:
Error: ENOSYS: function not implemented, copyfile 'demo.txt' -> 'copy.txt'] {
errno: -4054,
code: 'ENOSYS',
syscall: 'copyfile',
path: 'demo.txt',
dest: 'copy.txt'
}
nodejs的官方文档说“fs.constants.COPYFILE_FICLONE_FORCE:复制操作会尝试创建copy-on-write reflink。如果平台不支持copy-on-write,那么操作会失败。”
大多数服务器操作系统应该是 windows server 或 linux。
我确定nodejs的开发者不会开发一个不起作用的功能,所以我想知道“fs.constants.COPYFILE_FICLONE_FORCE”文件复制方法在哪些平台上可用。 Darwin、BSD 还是其他一些操作系统?
以下是一些参考资料:
node version: v16.14.2
windows version: windows 10
windows file system: NTFS
linux version: 5.10.109-1-MANJARO
linux core version: 5.10
linux file system: ext4
【问题讨论】:
-
我以为是文件系统功能? unix.stackexchange.com/questions/393305/…
-
你使用什么文件系统?
-
@jabaa linux文件系统为ext4,windows文件系统为NTFS
-
Node.js 最初是由 Joyent 赞助和大力开发的。 Joyent 曾经/也是 Illumos 的大力支持者(它基于 OpenSolaris,它基于 Solaris 是 Sun 和后来的 Oracle 销售的 BSD 发行版)。在早期,节点在 Illumos 上进行了严格测试。令人惊讶的是.. Illumos 的默认文件系统是 ZFS,它具有写时复制
标签: node.js