Use Node SQLite libraries for backup verification, if available
Some checks failed
CI/CD Pipeline / Test on Node.js 16.x and ubuntu-latest (release) Successful in 1m37s
CI/CD Pipeline / Test on Node.js 18.x and ubuntu-latest (release) Successful in 43s
CI/CD Pipeline / Test on Node.js 20.x and ubuntu-latest (release) Successful in 45s
CI/CD Pipeline / Test on Node.js 22.x and ubuntu-latest (release) Successful in 50s
CI/CD Pipeline / Lint and Code Quality (release) Failing after 11s
CI/CD Pipeline / Security Scan (release) Failing after 11s
CI/CD Pipeline / Test on Node.js 16.x and windows-latest (release) Has been cancelled
CI/CD Pipeline / Test on Node.js 18.x and macos-latest (release) Has been cancelled
CI/CD Pipeline / Test on Node.js 18.x and windows-latest (release) Has been cancelled
CI/CD Pipeline / Test on Node.js 20.x and macos-latest (release) Has been cancelled
CI/CD Pipeline / Test on Node.js 20.x and windows-latest (release) Has been cancelled
CI/CD Pipeline / Test on Node.js 22.x and macos-latest (release) Has been cancelled
CI/CD Pipeline / Test on Node.js 22.x and windows-latest (release) Has been cancelled
CI/CD Pipeline / Publish to npm (release) Has been cancelled
CI/CD Pipeline / Auto-increment version on main (release) Has been cancelled

This commit is contained in:
Skylar Ittner 2026-01-23 22:33:09 -07:00 committed by GitHub
parent b34e4b5d83
commit c2b4a8eca3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -114,9 +114,27 @@ class SQLiteBackup {
return false;
}
const dbDriver = this._getDatabaseDriver();
var result = "";
switch (dbDriver.type) {
case "cli":
const command = `sqlite3 "${backupPath}" "PRAGMA integrity_check;"`;
const {stdout} = await execAsync(command);
return stdout.trim() === 'ok';
result = stdout.trim();
break;
case "better-sqlite3":
const db = dbDriver.driver(backupPath);
result = await db.pragma('integrity_check', {simple: true});
break;
case "sqlite3":
result = await this._validateUsingSQLite3Package(dbDriver.driver, backupPath);
console.log(result);
break;
}
return result === 'ok';
} catch (error) {
return false;
}
@ -212,7 +230,6 @@ class SQLiteBackup {
isValid: null,
checksum: null
};
if (includeChecksums) {
backup.checksum = await this._calculateChecksum(file.path);
backup.isValid = await this.verifyBackup(file.path);
@ -390,6 +407,25 @@ class SQLiteBackup {
});
}
async _validateUsingSQLite3Package(driver, databasePath) {
return new Promise((resolve, reject) => {
const db = new driver.Database(databasePath, driver.OPEN_READONLY, err => {
if (err) {
return resolve("fail");
}
});
db.get("PRAGMA integrity_check", function (err, res) {
console.log(res);
if (typeof res == 'undefined') {
resolve("fail");
} else {
resolve(res.integrity_check ?? "fail");
}
});
});
}
async _backupUsingCopy(backupPath) {
fs.copyFileSync(this.databasePath, backupPath);
}
@ -434,7 +470,8 @@ class SQLiteBackup {
_matchesPattern(filename, pattern) {
// Simple pattern matching - could be enhanced with a proper glob library
if (pattern === '*' || pattern === '*.*') return true;
if (pattern === '*' || pattern === '*.*')
return true;
if (pattern.startsWith('*.')) {
const extension = pattern.slice(2);
return filename.endsWith('.' + extension);
@ -454,7 +491,8 @@ class BackupUtils {
*/
static formatSize(bytes) {
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
if (bytes === 0) return '0 B';
if (bytes === 0)
return '0 B';
const i = Math.floor(Math.log(bytes) / Math.log(1024));
return `${(bytes / Math.pow(1024, i)).toFixed(2)} ${sizes[i]}`;
}
@ -465,8 +503,10 @@ class BackupUtils {
* @returns {string} Formatted duration string
*/
static formatDuration(milliseconds) {
if (milliseconds < 1000) return `${milliseconds}ms`;
if (milliseconds < 60000) return `${(milliseconds / 1000).toFixed(2)}s`;
if (milliseconds < 1000)
return `${milliseconds}ms`;
if (milliseconds < 60000)
return `${(milliseconds / 1000).toFixed(2)}s`;
return `${(milliseconds / 60000).toFixed(2)}m`;
}