kibana/src/dev/build/tasks/assert_file_time.ts
Jonathan Budzenski ddc89841a3
[build] Remove default timestamp fix, assert timestamps are valid (#138345)
* [build] Remove default timestamp fix, assert timestamps are valid

* text

* fix date

* remove test
2022-08-09 14:24:36 -05:00

47 lines
1.6 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { resolve } from 'path';
import { statSync } from 'fs';
import { tap, filter, map, toArray } from 'rxjs/operators';
import { scan$, Task } from '../lib';
export const AssertFileTime: Task = {
description: 'Checking for files dated before 1980',
async run(config, log, build) {
const buildRoot = build.resolvePath();
await scan$(buildRoot)
.pipe(
map((path) => resolve(buildRoot, path)),
filter((file) => {
const { atimeMs, mtimeMs, ctimeMs } = statSync(file);
// tarred files with timestamps before 1970 throw errors
// zipped files with timestamps before 1980 throw errors
// round up to 1981 to avoid timezones
const invalidDate = new Date(1981, 0, 1).getTime();
return invalidDate > atimeMs || invalidDate > mtimeMs || invalidDate > ctimeMs;
}),
toArray(),
tap((invalidDates) => {
if (!invalidDates.length) {
return;
}
throw new Error(
'Archive errors occur with file times before 1980. The following files have errors:' +
'\n - ' +
invalidDates.join('\n - ')
);
})
)
.toPromise();
},
};