本文整理汇总了TypeScript中vs/base/node/extfs.sanitizeFilePath函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sanitizeFilePath函数的具体用法?TypeScript sanitizeFilePath怎么用?TypeScript sanitizeFilePath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sanitizeFilePath函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: String
const result = args.map(arg => {
let pathCandidate = String(arg);
let parsedPath: IPathWithLineAndColumn | undefined = undefined;
if (gotoLineMode) {
parsedPath = parseLineAndColumnAware(pathCandidate);
pathCandidate = parsedPath.path;
}
if (pathCandidate) {
pathCandidate = preparePath(cwd, pathCandidate);
}
const sanitizedFilePath = sanitizeFilePath(pathCandidate, cwd);
const basename = path.basename(sanitizedFilePath);
if (basename /* can be empty if code is opened on root */ && !extpath.isValidBasename(basename)) {
return null; // do not allow invalid file names
}
if (gotoLineMode && parsedPath) {
parsedPath.path = sanitizedFilePath;
return toPath(parsedPath);
}
return sanitizedFilePath;
});
示例2: resolveSingleFolderWorkspaceInitializationPayload
private resolveSingleFolderWorkspaceInitializationPayload(folderUri: ISingleFolderWorkspaceIdentifier): Promise<ISingleFolderWorkspaceInitializationPayload | undefined> {
// Return early the folder is not local
if (folderUri.scheme !== Schemas.file) {
return Promise.resolve({ id: createHash('md5').update(folderUri.toString()).digest('hex'), folder: folderUri });
}
function computeLocalDiskFolderId(folder: uri, stat: fs.Stats): string {
let ctime: number | undefined;
if (isLinux) {
ctime = stat.ino; // Linux: birthtime is ctime, so we cannot use it! We use the ino instead!
} else if (isMacintosh) {
ctime = stat.birthtime.getTime(); // macOS: birthtime is fine to use as is
} else if (isWindows) {
if (typeof stat.birthtimeMs === 'number') {
ctime = Math.floor(stat.birthtimeMs); // Windows: fix precision issue in node.js 8.x to get 7.x results (see https://github.com/nodejs/node/issues/19897)
} else {
ctime = stat.birthtime.getTime();
}
}
// we use the ctime as extra salt to the ID so that we catch the case of a folder getting
// deleted and recreated. in that case we do not want to carry over previous state
return createHash('md5').update(folder.fsPath).update(ctime ? String(ctime) : '').digest('hex');
}
// For local: ensure path is absolute and exists
const sanitizedFolderPath = sanitizeFilePath(folderUri.fsPath, process.env['VSCODE_CWD'] || process.cwd());
return stat(sanitizedFolderPath).then(stat => {
const sanitizedFolderUri = uri.file(sanitizedFolderPath);
return {
id: computeLocalDiskFolderId(sanitizedFolderUri, stat),
folder: sanitizedFolderUri
} as ISingleFolderWorkspaceInitializationPayload;
}, error => onUnexpectedError(error));
}