mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-08 06:54:24 +00:00
refactor(infra): share windows path normalization helper
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import path from "node:path";
|
||||
import { normalizeWindowsPathForComparison } from "../infra/path-guards.js";
|
||||
import { resolveSandboxInputPath } from "./sandbox-paths.js";
|
||||
|
||||
type RelativePathOptions = {
|
||||
@@ -8,17 +9,6 @@ type RelativePathOptions = {
|
||||
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: {
|
||||
root: string;
|
||||
candidate: string;
|
||||
|
||||
@@ -3,7 +3,7 @@ import path from "node:path";
|
||||
const NOT_FOUND_CODES = new Set(["ENOENT", "ENOTDIR"]);
|
||||
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);
|
||||
if (normalized.startsWith("\\\\?\\")) {
|
||||
normalized = normalized.slice(4);
|
||||
|
||||
Reference in New Issue
Block a user