mirror of
https://github.com/dtzp555-max/ocp.git
synced 2026-07-22 05:25:08 +00:00
fix(scripts): CLI entrypoint guard resilient to symlinked install paths
Bug found via integration test on MacBook Pro (macOS /tmp → /private/tmp):
`import.meta.url === \`file://\${process.argv[1]}\`` evaluates false when
the install path traverses a symlink, because import.meta.url is canonicalised
but process.argv[1] is not. Result: ./ocp doctor (and ./ocp update via
upgrade.mjs) exit silently with code 0 and no output, instead of running.
Fix: use fileURLToPath + realpathSync on both sides of the comparison.
Affects any install at a symlinked path (/tmp, NFS mounts, /var/ paths,
docker bind mounts, etc.). Normal ~/ocp installs were unaffected.
No cli.js citation needed: this is OCP-internal CLI dispatch with no
corresponding cli.js operation.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+11
-2
@@ -178,8 +178,17 @@ export async function runDoctor(opts = {}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// CLI entrypoint
|
// CLI entrypoint — use fileURLToPath + realpath to handle symlinked install paths
|
||||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
// (e.g. /tmp/ → /private/tmp/ on macOS would otherwise miss the guard).
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
import { realpathSync } from "node:fs";
|
||||||
|
function _isMain() {
|
||||||
|
if (!process.argv[1]) return false;
|
||||||
|
try {
|
||||||
|
return realpathSync(fileURLToPath(import.meta.url)) === realpathSync(process.argv[1]);
|
||||||
|
} catch { return false; }
|
||||||
|
}
|
||||||
|
if (_isMain()) {
|
||||||
const wantJson = process.argv.includes("--json");
|
const wantJson = process.argv.includes("--json");
|
||||||
const result = await runDoctor();
|
const result = await runDoctor();
|
||||||
if (wantJson) {
|
if (wantJson) {
|
||||||
|
|||||||
+10
-2
@@ -280,8 +280,16 @@ async function runRollback(opts) {
|
|||||||
return { path: "rollback", executed: true, changed: true, target: target.path, phases };
|
return { path: "rollback", executed: true, changed: true, target: target.path, phases };
|
||||||
}
|
}
|
||||||
|
|
||||||
// CLI entrypoint
|
// CLI entrypoint — use fileURLToPath + realpath to handle symlinked install paths.
|
||||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
import { fileURLToPath } from "node:url";
|
||||||
|
import { realpathSync } from "node:fs";
|
||||||
|
function _isMain() {
|
||||||
|
if (!process.argv[1]) return false;
|
||||||
|
try {
|
||||||
|
return realpathSync(fileURLToPath(import.meta.url)) === realpathSync(process.argv[1]);
|
||||||
|
} catch { return false; }
|
||||||
|
}
|
||||||
|
if (_isMain()) {
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
const dryRun = args.includes("--dry-run");
|
const dryRun = args.includes("--dry-run");
|
||||||
const yes = args.includes("--yes");
|
const yes = args.includes("--yes");
|
||||||
|
|||||||
Reference in New Issue
Block a user