Path: blob/master/src/packages/project/browser-websocket/realpath.ts
1447 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45// path is assumed relative to the HOME directory6// return value is also relative to HOME directory -- if it is7// a symlink to something outside of the HOME directory, we just8// return the input! This is used for sync so this is the best9// we can do for now (see https://github.com/sagemathinc/cocalc/issues/4732)10import { realpath as fs_realpath } from "node:fs/promises";1112// SMC_LOCAL_HUB_HOME is used for developing cocalc inside cocalc...13const HOME: string =14process.env.SMC_LOCAL_HUB_HOME ?? process.env.HOME ?? "/home/user";1516export async function realpath(path: string): Promise<string> {17const fullpath = HOME + "/" + path;18const rpath = await fs_realpath(fullpath);19if (rpath == fullpath || !rpath.startsWith(HOME + "/")) {20return path;21}22return rpath.slice((HOME + "/").length);23}242526