66'use strict' ;
77
88import paths = require( 'path' ) ;
9- import cp = require( 'child_process' ) ;
109import fs = require( 'fs' ) ;
1110import os = require( 'os' ) ;
1211import crypto = require( 'crypto' ) ;
@@ -614,61 +613,34 @@ export class FileService implements IFileService {
614613 // 2.) write to a temporary file to be able to copy over later
615614 const tmpPath = paths . join ( this . tmpPath , `code-elevated-${ Math . random ( ) . toString ( 36 ) . replace ( / [ ^ a - z ] + / g, '' ) . substr ( 0 , 6 ) } ` ) ;
616615 return this . updateContent ( uri . file ( tmpPath ) , value , writeOptions ) . then ( ( ) => {
617- let sudoPromise : Thenable < void > ;
618-
619- // Windows: Use code-writer.exe helper
620- if ( isWindows ) {
621- sudoPromise = new TPromise < void > ( ( c , e ) => {
622- let codeWriter : string ;
623- if ( process . arch === 'x64' ) {
624- codeWriter = uri . parse ( require . toUrl ( 'vs/workbench/services/files/node/elevate/win32/code-writer-x64.exe' ) ) . fsPath ;
625- } else {
626- codeWriter = uri . parse ( require . toUrl ( 'vs/workbench/services/files/node/elevate/win32/code-writer-ia32.exe' ) ) . fsPath ;
616+
617+ // 3.) invoke our CLI as super user
618+ return ( import ( 'sudo-prompt' ) ) . then ( sudoPrompt => {
619+ return new TPromise < void > ( ( c , e ) => {
620+ const promptOptions = { name : this . options . elevationSupport . promptTitle . replace ( '-' , '' ) , icns : this . options . elevationSupport . promptIcnsPath } ;
621+
622+ const sudoCommand : string [ ] = [ `"${ this . options . elevationSupport . cliPath } "` ] ;
623+ if ( options . overwriteReadonly ) {
624+ sudoCommand . push ( '--sudo-chmod' ) ;
627625 }
626+ sudoCommand . push ( '--sudo-write' , `"${ tmpPath } "` , `"${ absolutePath } "` ) ;
628627
629- cp . exec ( `" ${ codeWriter } " " ${ tmpPath } " " ${ absolutePath } "` , ( error , stdout , stderr ) => {
628+ sudoPrompt . exec ( sudoCommand . join ( ' ' ) , promptOptions , ( error : string , stdout : string , stderr : string ) => {
630629 if ( error || stderr ) {
631630 e ( error || stderr ) ;
632631 } else {
633632 c ( void 0 ) ;
634633 }
635634 } ) ;
636635 } ) ;
637- }
638-
639- // Mac/Linux: Use sudo-prompt
640- else {
641- sudoPromise = ( import ( 'sudo-prompt' ) ) . then ( sudoPrompt => {
642- return new TPromise < void > ( ( c , e ) => {
643- const promptOptions = { name : this . options . elevationSupport . promptTitle . replace ( '-' , '' ) , icns : this . options . elevationSupport . promptIcnsPath } ;
644-
645- const sudoCommand : string [ ] = [ `"${ this . options . elevationSupport . cliPath } "` ] ;
646- if ( options . overwriteReadonly ) {
647- sudoCommand . push ( '--sudo-chmod' ) ;
648- }
649- sudoCommand . push ( '--sudo-write' , `"${ tmpPath } "` , `"${ absolutePath } "` ) ;
650-
651- sudoPrompt . exec ( sudoCommand . join ( ' ' ) , promptOptions , ( error : string , stdout : string , stderr : string ) => {
652- if ( error || stderr ) {
653- e ( error || stderr ) ;
654- } else {
655- c ( void 0 ) ;
656- }
657- } ) ;
658- } ) ;
659- } ) ;
660- }
661-
662- // 3.) invoke our CLI as super user
663- return sudoPromise . then ( ( ) => {
636+ } ) . then ( ( ) => {
664637
665638 // 3.) delete temp file
666639 return pfs . del ( tmpPath , this . tmpPath ) . then ( ( ) => {
667640
668641 // 4.) resolve again
669642 return this . resolve ( resource ) ;
670643 } ) ;
671-
672644 } ) ;
673645 } ) ;
674646 } ) . then ( null , error => {
@@ -1284,4 +1256,4 @@ export class StatResolver {
12841256 } ) ;
12851257 } ) ;
12861258 }
1287- }
1259+ }
0 commit comments