mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 22:25:24 +00:00
27 lines
956 B
TypeScript
27 lines
956 B
TypeScript
export function normalizeRemoteDir(remotePath: string): string {
|
|
const trimmed = remotePath.trim().replace(/\\/g, "/");
|
|
if (!trimmed) return "/";
|
|
const collapsed = trimmed.replace(/\/+/g, "/");
|
|
const absolute = collapsed.startsWith("/") ? collapsed : `/${collapsed}`;
|
|
if (absolute === "/") return "/";
|
|
return absolute.replace(/\/+$/, "");
|
|
}
|
|
|
|
export function joinRemotePath(basePath: string, childPath: string): string {
|
|
const base = normalizeRemoteDir(basePath);
|
|
const child = childPath.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
if (!child) return base;
|
|
return base === "/" ? `/${child}` : `${base}/${child}`;
|
|
}
|
|
|
|
export function hasSameHostTransferConflict(
|
|
sourcePaths: string[],
|
|
destinationDir: string,
|
|
): boolean {
|
|
const dest = normalizeRemoteDir(destinationDir);
|
|
return sourcePaths.some((sourcePath) => {
|
|
const source = normalizeRemoteDir(sourcePath);
|
|
return dest === source || dest.startsWith(`${source}/`);
|
|
});
|
|
}
|