How to use the utimesSync function from fs

Find comprehensive JavaScript fs.utimesSync code examples handpicked from public code repositorys.

91
92
93
94
95
96
97
98
99
100
exports.truncateSync = fs.truncateSync;
exports.unlink = co.promisify(fs.unlink);
exports.unlinkSync = fs.unlinkSync;
exports.unwatchFile = fs.unwatchFile;
exports.utimes = co.promisify(fs.utimes);
exports.utimesSync = fs.utimesSync;
exports.watch = fs.watch;
exports.watchFile = fs.watchFile;
exports.write = co.promisify(fs.write);
exports.writeSync = fs.writeSync;
fork icon22
star icon45
watch icon26

126
127
128
129
130
131
132
133
134
135

//
// test synchronized code paths, these functions throw on failure
//
function syncTests() {
  fs.utimesSync(pathType(tmpdir.path), atime, mtime);
  expect_ok('utimesSync', tmpdir.path, undefined, atime, mtime);

  fs.lutimesSync(pathType(lpath), atime, mtime);
  expect_ok('lutimesSync', lpath, undefined, atime, mtime, fs.lstatSync);
fork icon42
star icon19
watch icon0

+ 7 other calls in file

627
628
629
630
631
632
633
634
635
636
637
638


  fs.utimes(nonexistentFile, new Date(), new Date(),
            common.mustCall(validateError));


  assert.throws(
    () => fs.utimesSync(nonexistentFile, new Date(), new Date()),
    validateError
  );
}

fork icon42
star icon19
watch icon0

761
762
763
764
765
766
767
768
769
770
const mtime = entry.mtime
try {
  fs.futimesSync(fd, atime, mtime)
} catch (futimeser) {
  try {
    fs.utimesSync(entry.absolute, atime, mtime)
  } catch (utimeser) {
    er = futimeser
  }
}
fork icon3
star icon2
watch icon0

50
51
52
53
54
55
56
57
58
59
    }
    fs.unlinkSync(destPath);
    fs.copyFileSync(srcPath, destPath);
    // Set the mtime of the copied file to be same as the original file,
    // so that the above check works.
    fs.utimesSync(destPath, srcStat.atime, srcStat.mtime);
  }
} else {
  fs.copyFileSync(srcPath, destPath);
  fs.utimesSync(destPath, srcStat.atime, srcStat.mtime);
fork icon0
star icon1
watch icon0

+ 3 other calls in file

89
90
91
92
93
94
95
96
97
98
}

var err;
err = undefined;
try {
  fs.utimesSync('foobarbaz', atime, mtime);
} catch (ex) {
  err = ex;
}
expect_errno('utimesSync', 'foobarbaz', err, 'ENOENT');
fork icon0
star icon0
watch icon0