copy-file.js 607 B

12345678910111213141516171819202122
  1. const fs = require('./fs.js')
  2. const getOptions = require('./common/get-options.js')
  3. const owner = require('./common/owner.js')
  4. const copyFile = async (src, dest, opts) => {
  5. const options = getOptions(opts, {
  6. copy: ['mode', 'owner'],
  7. wrap: 'mode',
  8. })
  9. const { uid, gid } = await owner.validate(dest, options.owner)
  10. // the node core method as of 16.5.0 does not support the mode being in an
  11. // object, so we have to pass the mode value directly
  12. const result = await fs.copyFile(src, dest, options.mode)
  13. await owner.update(dest, uid, gid)
  14. return result
  15. }
  16. module.exports = copyFile