test: relax Y2K38 check in test-fs-utimes-y2K38

On some platforms `date` may not support the `-r` option. Optimistically
allow the test to proceed in that case as the previous `touch` had
succeeded -- we were just not able to easily validate the file date.

PR-URL: https://github.com/nodejs/node/pull/37825
Refs: https://github.com/nodejs/node/pull/37707
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Richard Lau authored and James M Snell committed 2021-03-22 08:16:13 -07:00
1 parent 6ea652d6ec
commit 428c3fd31b
1 file changed
+14 -11
+14 -11
View File
@@ -1,20 +1,15 @@
'use strict';
const common = require('../common');
if (common.isIBMi) {
common.skip('fs.utimesSync() currently fails on IBM i with Y2K38 values');
}
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const assert = require('assert');
const fs = require('fs');
// Check for Y2K38 support. For Windows and AIX, assume it's there. Windows
// Check for Y2K38 support. For Windows, assume it's there. Windows
// doesn't have `touch` and `date -r` which are used in the check for support.
// AIX lacks `date -r`.
if (!common.isWindows && !common.isAIX) {
if (!common.isWindows) {
const testFilePath = `${tmpdir.path}/y2k38-test`;
const testFileDate = '204001020304';
const { spawnSync } = require('child_process');
@@ -25,13 +20,21 @@ if (!common.isWindows && !common.isAIX) {
common.skip('File system appears to lack Y2K38 support (touch failed)');
}
// On some file systems that lack Y2K38 support, `touch` will succeed but
// the time will be incorrect.
const dateResult = spawnSync('date',
['-r', testFilePath, '+%Y%m%d%H%M'],
{ encoding: 'utf8' });
assert.strictEqual(dateResult.status, 0);
if (dateResult.stdout.trim() !== testFileDate) {
common.skip('File system appears to lack Y2k38 support (date failed)');
if (dateResult.status === 0) {
if (dateResult.stdout.trim() !== testFileDate) {
common.skip('File system appears to lack Y2k38 support (date failed)');
}
} else {
// On some platforms `date` may not support the `-r` option. Usually
// this will result in a non-zero status and usage information printed.
// In this case optimistically proceed -- the earlier `touch` succeeded
// but validation that the file has the correct time is not easily possible.
assert.match(dateResult.stderr, /[Uu]sage:/);
}
}