


















@@ -47,7 +47,7 @@ export function copyBundledPluginRuntimeRoot(sourceRoot: string, targetRoot: str
4747if (path.resolve(sourceRoot) === path.resolve(targetRoot)) {
4848return;
4949}
50-fs.mkdirSync(targetRoot, { recursive: true, mode: 0o755 });
50+ensureBundledRuntimeMirrorDirectory(targetRoot);
5151const mirroredNames = new Set<string>();
5252for (const entry of fs.readdirSync(sourceRoot, { withFileTypes: true })) {
5353if (shouldIgnoreBundledRuntimeMirrorEntry(entry.name)) {
@@ -81,16 +81,13 @@ export function materializeBundledRuntimeMirrorFile(sourcePath: string, targetPa
8181return;
8282}
8383try {
84-if (
85-fs.realpathSync(sourcePath) === fs.realpathSync(targetPath) &&
86-!fs.lstatSync(targetPath).isSymbolicLink()
87-) {
84+if (isBundledRuntimeMirrorFileAlreadyMaterialized(sourcePath, targetPath)) {
8885return;
8986}
9087} catch {
9188// Missing targets are expected before the mirror file is materialized.
9289}
93-fs.mkdirSync(path.dirname(targetPath), { recursive: true, mode: 0o755 });
90+ensureBundledRuntimeMirrorDirectory(path.dirname(targetPath));
9491removeBundledRuntimeMirrorPathIfTypeChanged(targetPath, "file");
9592const tempPath = createBundledRuntimeMirrorTempPath(targetPath);
9693try {
@@ -107,6 +104,20 @@ export function materializeBundledRuntimeMirrorFile(sourcePath: string, targetPa
107104}
108105}
109106107+function isBundledRuntimeMirrorFileAlreadyMaterialized(
108+sourcePath: string,
109+targetPath: string,
110+): boolean {
111+const sourceStat = fs.lstatSync(sourcePath);
112+const targetStat = fs.lstatSync(targetPath);
113+return (
114+sourceStat.isFile() &&
115+targetStat.isFile() &&
116+sourceStat.dev === targetStat.dev &&
117+sourceStat.ino === targetStat.ino
118+);
119+}
120+110121function chmodBundledRuntimeMirrorFileReadable(sourcePath: string, targetPath: string): void {
111122try {
112123const sourceMode = fs.statSync(sourcePath).mode;
@@ -131,6 +142,21 @@ function pruneStaleBundledRuntimeMirrorEntries(
131142}
132143}
133144145+function ensureBundledRuntimeMirrorDirectory(targetRoot: string): void {
146+try {
147+const stat = fs.lstatSync(targetRoot);
148+if (stat.isDirectory() && !stat.isSymbolicLink()) {
149+return;
150+}
151+fs.rmSync(targetRoot, { recursive: true, force: true });
152+} catch (error) {
153+if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
154+throw error;
155+}
156+}
157+fs.mkdirSync(targetRoot, { recursive: true, mode: 0o755 });
158+}
159+134160function removeBundledRuntimeMirrorPathIfTypeChanged(
135161targetPath: string,
136162expectedType: "directory" | "file" | "symlink",
@@ -153,7 +179,7 @@ function removeBundledRuntimeMirrorPathIfTypeChanged(
153179}
154180155181function replaceBundledRuntimeMirrorSymlinkAtomic(linkTarget: string, targetPath: string): void {
156-fs.mkdirSync(path.dirname(targetPath), { recursive: true, mode: 0o755 });
182+ensureBundledRuntimeMirrorDirectory(path.dirname(targetPath));
157183const tempPath = createBundledRuntimeMirrorTempPath(targetPath);
158184try {
159185fs.symlinkSync(linkTarget, tempPath);
@@ -164,7 +190,7 @@ function replaceBundledRuntimeMirrorSymlinkAtomic(linkTarget: string, targetPath
164190}
165191166192function copyBundledRuntimeMirrorFileAtomic(sourcePath: string, targetPath: string): void {
167-fs.mkdirSync(path.dirname(targetPath), { recursive: true, mode: 0o755 });
193+ensureBundledRuntimeMirrorDirectory(path.dirname(targetPath));
168194const tempPath = createBundledRuntimeMirrorTempPath(targetPath);
169195try {
170196fs.copyFileSync(sourcePath, tempPath);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。