mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
refactor(infra): share windows path normalization helper
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
import { normalizeWindowsPathForComparison } from "../infra/path-guards.js";
|
||||||
import { resolveSandboxInputPath } from "./sandbox-paths.js";
|
import { resolveSandboxInputPath } from "./sandbox-paths.js";
|
||||||
|
|
||||||
type RelativePathOptions = {
|
type RelativePathOptions = {
|
||||||
@@ -8,17 +9,6 @@ type RelativePathOptions = {
|
|||||||
includeRootInError?: boolean;
|
includeRootInError?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
function normalizeWindowsPathForComparison(input: string): string {
|
|
||||||
let normalized = path.win32.normalize(input);
|
|
||||||
if (normalized.startsWith("\\\\?\\")) {
|
|
||||||
normalized = normalized.slice(4);
|
|
||||||
if (normalized.toUpperCase().startsWith("UNC\\")) {
|
|
||||||
normalized = `\\\\${normalized.slice(4)}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return normalized.replaceAll("/", "\\").toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
function toRelativePathUnderRoot(params: {
|
function toRelativePathUnderRoot(params: {
|
||||||
root: string;
|
root: string;
|
||||||
candidate: string;
|
candidate: string;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import path from "node:path";
|
|||||||
const NOT_FOUND_CODES = new Set(["ENOENT", "ENOTDIR"]);
|
const NOT_FOUND_CODES = new Set(["ENOENT", "ENOTDIR"]);
|
||||||
const SYMLINK_OPEN_CODES = new Set(["ELOOP", "EINVAL", "ENOTSUP"]);
|
const SYMLINK_OPEN_CODES = new Set(["ELOOP", "EINVAL", "ENOTSUP"]);
|
||||||
|
|
||||||
function normalizeWindowsPathForComparison(input: string): string {
|
export function normalizeWindowsPathForComparison(input: string): string {
|
||||||
let normalized = path.win32.normalize(input);
|
let normalized = path.win32.normalize(input);
|
||||||
if (normalized.startsWith("\\\\?\\")) {
|
if (normalized.startsWith("\\\\?\\")) {
|
||||||
normalized = normalized.slice(4);
|
normalized = normalized.slice(4);
|
||||||
|
|||||||
Reference in New Issue
Block a user