From 9ffcd2f21a3438c8298e3fee3ecc4882cf89b401 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Thu, 26 Mar 2020 00:13:20 -0400 Subject: [PATCH] Switches to use fs.realpath.native instead of wmic --- src/git/gitService.ts | 10 +++++++--- src/git/shell.ts | 20 +------------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/git/gitService.ts b/src/git/gitService.ts index 9c2374e..9f4fb5a 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -83,7 +83,7 @@ import { import { GitUri } from './gitUri'; import { RemoteProvider, RemoteProviderFactory, RemoteProviders, RemoteProviderWithApi } from './remotes/factory'; import { GitReflogParser, GitShortLogParser } from './parsers/parsers'; -import { fsExists, getNetworkPathForDrive, isWindows } from './shell'; +import { fsExists, isWindows } from './shell'; import { GitRevision, PullRequest, PullRequestDateFormatting } from './models/models'; export * from './gitUri'; @@ -2601,8 +2601,12 @@ export class GitService implements Disposable { const [, letter] = match; try { - const networkPath = await getNetworkPathForDrive(letter); - if (networkPath != null) { + const networkPath = await new Promise(resolve => + fs.realpath.native(`${letter}:`, { encoding: 'utf8' }, (err, resolvedPath) => + resolve(err != null ? undefined : resolvedPath), + ), + ); + if (networkPath !== undefined) { return Strings.normalizePath( repoUri.fsPath.replace(networkPath, `${letter.toLowerCase()}:`), ); diff --git a/src/git/shell.ts b/src/git/shell.ts index 04a6311..f97c58b 100644 --- a/src/git/shell.ts +++ b/src/git/shell.ts @@ -1,8 +1,7 @@ 'use strict'; -import { exec, execFile } from 'child_process'; +import { execFile } from 'child_process'; import * as fs from 'fs'; import * as paths from 'path'; -import { promisify } from 'util'; import * as iconv from 'iconv-lite'; import { Logger } from '../logger'; @@ -191,20 +190,3 @@ export function run( export function fsExists(path: string) { return new Promise(resolve => fs.exists(path, exists => resolve(exists))); } - -const networkDriveRegex = /([A-Z]):\s+(.*?)\s*$/m; - -export async function getNetworkPathForDrive(letter: string): Promise { - const result = await promisify(exec)( - `wmic logicaldisk where 'drivetype=4 and deviceid="${letter}:"' get deviceid,providername`, - { - maxBuffer: 2000 * 1024, - }, - ); - - const match = networkDriveRegex.exec(result.stdout); - if (match == null) return undefined; - - const [, , path] = match; - return path; -}