當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript extfs.sanitizeFilePath函數代碼示例

本文整理匯總了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;
	});
開發者ID:joelday,項目名稱:vscode,代碼行數:28,代碼來源:paths.ts

示例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));
	}
開發者ID:joelday,項目名稱:vscode,代碼行數:36,代碼來源:main.ts


注:本文中的vs/base/node/extfs.sanitizeFilePath函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。