Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit feae11c

Browse files
committed
fix codegraph sync error on SMB/CIFS drive
预过滤器(src/extraction/index.ts:1354),用于在读取/哈希文件之前跳过未改变的文件。在网络驱动器(SMB/CIFS,比如你的 Z: 盘)上,Windows SMB客户端可能缓存文件的旧 mtime,导致预过滤器错误地跳过了已修改的文件,最终报告"Already up to date"。
1 parent e87bc35 commit feae11c

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

src/bin/codegraph.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,9 @@ program
628628
program
629629
.command('sync [path]')
630630
.description('Sync changes since last index')
631+
.option('-f, --force', 'Skip mtime/size pre-filter and hash every file (useful on network drives)')
631632
.option('-q, --quiet', 'Suppress output (for git hooks)')
632-
.action(async (pathArg: string | undefined, options: { quiet?: boolean }) => {
633+
.action(async (pathArg: string | undefined, options: { force?: boolean; quiet?: boolean }) => {
633634
const projectPath = resolveProjectPath(pathArg);
634635

635636
try {
@@ -644,7 +645,7 @@ program
644645
const cg = await CodeGraph.open(projectPath);
645646

646647
if (options.quiet) {
647-
await cg.sync();
648+
await cg.sync({ force: options.force });
648649
cg.destroy();
649650
return;
650651
}
@@ -657,6 +658,7 @@ program
657658

658659
const result = await cg.sync({
659660
onProgress: progress.onProgress,
661+
force: options.force,
660662
});
661663

662664
await progress.stop();

src/extraction/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ export class ExtractionOrchestrator {
12951295
* changes. This works in non-git projects and catches committed changes from
12961296
* `git pull`/`checkout`/`merge`/`rebase` that `git status` cannot see.
12971297
*/
1298-
async sync(onProgress?: (progress: IndexProgress) => void): Promise<SyncResult> {
1298+
async sync(onProgress?: (progress: IndexProgress) => void, force?: boolean): Promise<SyncResult> {
12991299
await initGrammars(); // Initialize WASM runtime (grammars loaded lazily below)
13001300
const startTime = Date.now();
13011301
let filesChecked = 0;
@@ -1346,12 +1346,9 @@ export class ExtractionOrchestrator {
13461346
const fullPath = path.join(this.rootDir, filePath);
13471347
const tracked = trackedMap.get(filePath);
13481348

1349-
// Cheap pre-filter: an already-indexed file whose size AND mtime both match
1350-
// the DB is unchanged — skip it without reading or hashing. (A content
1351-
// change that preserves both exactly is the blind spot every mtime-based
1352-
// incremental tool accepts; `index --force` is the escape hatch. Git bumps
1353-
// mtime on every file it writes during checkout/merge, so pulls are caught.)
1354-
if (tracked) {
1349+
// Cheap pre-filter: skip files whose size AND mtime both match the DB.
1350+
// Bypassed with force=true (e.g. network drives where mtime is unreliable).
1351+
if (tracked && !force) {
13551352
try {
13561353
const stat = fs.statSync(fullPath);
13571354
if (stat.size === tracked.size && Math.floor(stat.mtimeMs) === Math.floor(tracked.modifiedAt)) {

src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ export interface IndexOptions {
112112

113113
/** Enable verbose logging (worker lifecycle, memory, timeouts) */
114114
verbose?: boolean;
115+
116+
/**
117+
* Skip the mtime/size pre-filter and always read+hash every file.
118+
* Useful on network drives (SMB/CIFS) where mtime is not reliably updated.
119+
*/
120+
force?: boolean;
115121
}
116122

117123
/**
@@ -393,7 +399,7 @@ export class CodeGraph {
393399
return { filesChecked: 0, filesAdded: 0, filesModified: 0, filesRemoved: 0, nodesUpdated: 0, durationMs: 0 };
394400
}
395401
try {
396-
const result = await this.orchestrator.sync(options.onProgress);
402+
const result = await this.orchestrator.sync(options.onProgress, options.force);
397403

398404
// Resolve references if files were updated
399405
if (result.filesAdded > 0 || result.filesModified > 0) {

0 commit comments

Comments
 (0)