utimes.js 687 B

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict'
  2. const fs = require('../fs')
  3. const u = require('universalify').fromPromise
  4. async function utimesMillis (path, atime, mtime) {
  5. // if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback)
  6. const fd = await fs.open(path, 'r+')
  7. let closeErr = null
  8. try {
  9. await fs.futimes(fd, atime, mtime)
  10. } finally {
  11. try {
  12. await fs.close(fd)
  13. } catch (e) {
  14. closeErr = e
  15. }
  16. }
  17. if (closeErr) {
  18. throw closeErr
  19. }
  20. }
  21. function utimesMillisSync (path, atime, mtime) {
  22. const fd = fs.openSync(path, 'r+')
  23. fs.futimesSync(fd, atime, mtime)
  24. return fs.closeSync(fd)
  25. }
  26. module.exports = {
  27. utimesMillis: u(utimesMillis),
  28. utimesMillisSync
  29. }