Which os support copy-on-write?
04:11 25 Apr 2022

I try run the following code in Linux and 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)

Both failed, error message:

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'
}

Windows:

Error: ENOSYS: function not implemented, copyfile 'demo.txt' -> 'copy.txt'] {
  errno: -4054,
  code: 'ENOSYS',
  syscall: 'copyfile',
  path: 'demo.txt',
  dest: 'copy.txt'
}

The official documentation of nodejs says

fs.constants.COPYFILE_FICLONE_FORCE: The copy operation will attempt to create a copy-on-write reflink. If the platform does not support copy-on-write, then the operation will fail."

Most server operating systems should be Windows server or Linux.

I'm sure the developers of nodejs won't develop a feature that doesn't work, so I'd like to know on what platforms the "fs.constants.COPYFILE_FICLONE_FORCE" file copy method is available. Darwin, BSD, or some other OS?

Here is some reference information:

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
node.js copy-on-write