MCPcopy Create free account
hub / github.com/subquery/subql / resetFile

Method resetFile

packages/node-core/src/indexer/monitor.service.ts:363–381  ·  view source on GitHub ↗
(file: keyof typeof FileLocation)

Source from the content-addressed store, hash-verified

361 }
362
363 private resetFile(file: keyof typeof FileLocation): void {
364 const backupIndexPath = `${this.indexPath}.bak`;
365 try {
366 // Backup the original index file
367 const backupContent = fs.readFileSync(this.indexPath, 'utf-8');
368 fs.writeFileSync(backupIndexPath, backupContent, 'utf-8');
369 this.removeIndexEntriesByFile(file);
370 } catch (e) {
371 // Rollback by restoring the backup
372 const backupContent = fs.readFileSync(backupIndexPath, 'utf-8');
373 fs.writeFileSync(this.indexPath, backupContent, 'utf-8');
374 fs.rmSync(backupIndexPath);
375 throw new Error(`Error during index removal: ${e}`);
376 }
377 // Only remove file when index is successful removed
378 fs.rmSync(this.getFilePath(file));
379 fs.rmSync(backupIndexPath);
380 this.createOrResetFile(this.getFilePath(file));
381 }
382
383 private getFileSize(file: keyof typeof FileLocation): number {
384 const filePath = this.getFilePath(file);

Callers 2

switchToFileMethod · 0.95
testResetFileMethod · 0.80

Calls 3

getFilePathMethod · 0.95
createOrResetFileMethod · 0.95

Tested by 1

testResetFileMethod · 0.64