Skip to content

Commit f25632e

Browse files
kjkclaude
andcommitted
sync-bug-files: add logging, fix dot() recursion, rename shorter filenames to longer on match
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 38fcdf0 commit f25632e

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

cmd/sync-bug-files.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { readdirSync, renameSync, copyFileSync, statSync, existsSync } from "fs"
22
import { join } from "path";
33

44
function dot() {
5-
dot();
5+
process.stdout.write(".");
66
// @ts-ignore - Bun-specific API for flushing stdout
77
if (typeof Bun !== "undefined") Bun.stdout.flush?.();
88
}
@@ -119,9 +119,26 @@ function syncDirs(dirs: string[]) {
119119
const match = dstFiles.find((f) => f.bugNumber === srcFile.bugNumber && f.fileSize === srcFile.fileSize);
120120
if (match) {
121121
if (match.fileName !== srcFile.fileName) {
122-
console.log(
123-
`note: same bug #${srcFile.bugNumber}, same size, different names: "${srcFile.fileName}" vs "${match.fileName}"`,
124-
);
122+
// rename the shorter-named file to the longer name in both places
123+
const longer = srcFile.fileName.length >= match.fileName.length ? srcFile.fileName : match.fileName;
124+
const shorter = srcFile.fileName.length >= match.fileName.length ? match.fileName : srcFile.fileName;
125+
if (longer !== shorter) {
126+
// figure out which entry has the shorter name and rename it
127+
const shorterInSrc = srcFile.fileName === shorter;
128+
const renameDir = shorterInSrc ? srcDir : dstDir;
129+
const renameInfo = shorterInSrc ? srcFile : match;
130+
const oldPath = join(renameDir, shorter);
131+
const newPath = join(renameDir, longer);
132+
if (!existsSync(newPath)) {
133+
console.log(`rename: ${shorter} -> ${longer} in ${renameDir}`);
134+
renameSync(oldPath, newPath);
135+
renameInfo.fileName = longer;
136+
} else {
137+
console.log(
138+
`note: same bug #${srcFile.bugNumber}, same size, different names: "${srcFile.fileName}" vs "${match.fileName}" (cannot rename, target exists)`,
139+
);
140+
}
141+
}
125142
}
126143
continue;
127144
}

0 commit comments

Comments
 (0)