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

@@ -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",
}
}