fix: handle directory-to-non-directory conflict in copySnapshotPaths

When git ls-files returns directory entries (nested git repos),
cpSync fails trying to overwrite a file placeholder with a directory.
Now removes the conflicting target file before copying.
This commit is contained in:
Eyejoker
2026-03-30 00:36:36 +09:00
parent 09b2ec2b8e
commit 53ed437034

View File

@@ -218,6 +218,14 @@ function copySnapshotPaths(
if (!fs.existsSync(sourcePath)) continue;
const targetPath = path.join(targetDir, relativePath);
const srcStat = fs.statSync(sourcePath);
// When source is a directory (e.g. nested git repo listed by git ls-files),
// remove any conflicting non-directory at the target before copying.
if (srcStat.isDirectory()) {
if (fs.existsSync(targetPath) && !fs.statSync(targetPath).isDirectory()) {
fs.rmSync(targetPath, { force: true });
}
}
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
fs.cpSync(sourcePath, targetPath, { force: true, recursive: true });
}