ts tupctime

This commit is contained in:
Christopher Monsanto 2020-07-17 09:15:38 -04:00
parent ad51a0464b
commit dca677d52d
5 changed files with 51 additions and 7 deletions

View File

@ -50,13 +50,36 @@ importers:
typescript: ^3.9.7
tools/tupctime:
dependencies:
'@types/better-sqlite3': 5.4.0
'@types/debug': 4.1.5
'@types/node': 14.0.23
better-sqlite3: 7.0.1
debug: 4.1.1
devDependencies:
typescript: 3.9.7
specifiers:
'@types/better-sqlite3': ^5.4.0
'@types/debug': ^4.1.5
'@types/node': ^14.0.23
better-sqlite3: ^7.0.1
debug: ^4.1.1
typescript: ^3.9.7
lockfileVersion: 5.1
packages:
/@types/better-sqlite3/5.4.0:
dependencies:
'@types/integer': 1.0.1
dev: false
resolution:
integrity: sha512-nzm7lJ7l3jBmGUbtkL8cdOMhPkN6Pw2IM+b0V7iIKba+YKiLrjkIy7vVLsBIVnd7+lgzBzrHsXZxCaFTcmw5Ow==
/@types/debug/4.1.5:
dev: false
resolution:
integrity: sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==
/@types/integer/1.0.1:
dev: false
resolution:
integrity: sha512-DmZDpSVnsuBrOhtHwE1oKmUJ3qVjHhhNQ7WnZy9/RhH3A24Ar+9o4SoaCWcTzQhalpRDIAMsfdoZLWNJtdBR7A==
/@types/node/14.0.23:
dev: false
resolution:

View File

@ -40,7 +40,7 @@ AND name NOT IN ('^', '$')`);
const updateQuery = db.prepare(`UPDATE node SET mtime = ? WHERE id = ?`);
function update() {
const stack = [{isDir: true, id: 0, path: "."}];
const stack : {isDir: boolean, id : number, path: string, ctime?: bigint, name?: string}[] = [{isDir: true, id: 0, path: "."}];
let item;
while (item = stack.pop()) {
@ -57,11 +57,16 @@ function update() {
}
} else {
// bigint calculation is necessary to avoid rounding errors/spurious update
//
// typescript doesn't understand second argument to lstatSync, or
// that division can work between a number and bigint, so ignore
//
// @ts-ignore
const ctime = fs.lstatSync(item.path, {bigint: true}).ctimeMs / 1000n;
if (ctime !== item.ctime) {
debug(`Updating ${item.path}: ${ctime}, ${item.ctime}`);
if (updateQuery.run(ctime, item.id).changes !== 1)
throw new Error(`Couldn't update ${path}`);
throw new Error(`Couldn't update ${item.path}`);
}
}
}

View File

@ -1,7 +1,17 @@
{
"dependencies": {
"better-sqlite3":"^7.0.1",
"debug":"^4.1.1"
"@types/better-sqlite3": "^5.4.0",
"@types/debug": "^4.1.5",
"@types/node": "^14.0.23",
"better-sqlite3": "^7.0.1",
"debug": "^4.1.1"
},
"type": "module"
"type": "module",
"scripts": {
"prepare": "tsc"
},
"devDependencies": {
"typescript": "^3.9.7"
},
"main": "./dist/index.js"
}

View File

@ -0,0 +1,6 @@
{
"extends": "../../tsconfig-base",
"compilerOptions": {
"outDir": "dist",
}
}

View File

@ -1,8 +1,8 @@
{
"compilerOptions": {
"incremental": true,
"target": "es2018",
"lib": ["es2018"],
"target": "es2020",
"lib": ["es2020"],
"module": "esnext",
"jsx": "react",
"strict": true,