11import _ from 'lodash' ;
2- import * as fs from 'fs' ;
32import * as util from 'util' ;
43import * as os from 'os' ;
54import * as path from 'path' ;
65
7- import { canAccess , writeFile , moveFile , readFile , getRealPath } from '../../util/fs' ;
6+ import * as fs from '../../util/fs' ;
87import { logError } from '../../error-tracking' ;
98import { OVERRIDE_BIN_PATH } from './terminal-env-overrides' ;
109
@@ -15,16 +14,15 @@ const POSIX_OVERRIDE_BIN_PATH = process.platform === 'win32'
1514
1615const SHELL = ( process . env . SHELL || '' ) . split ( '/' ) . slice ( - 1 ) [ 0 ] ;
1716
18- const appendOrCreateFile = util . promisify ( fs . appendFile ) ;
1917const appendToFirstExisting = async ( paths : string [ ] , forceWrite : boolean , contents : string ) => {
2018 for ( let path of paths ) {
2119 // Follow the path through symlinks (relatively common for terminal config):
22- const realPath = await getRealPath ( path ) ;
20+ const realPath = await fs . getRealPath ( path ) ;
2321 if ( ! realPath ) continue ; // File (or linked file) does not exist
2422
25- if ( await canAccess ( realPath ) ) {
23+ if ( await fs . canAccess ( realPath ) ) {
2624 // Found our first valid readable file - append our extra config
27- return appendOrCreateFile ( realPath , contents ) ;
25+ return fs . appendOrCreateFile ( realPath , contents ) ;
2826 }
2927
3028 // ^ Small races here, if the file content/perms change between check and write, but
@@ -33,7 +31,7 @@ const appendToFirstExisting = async (paths: string[], forceWrite: boolean, conte
3331
3432 if ( forceWrite ) {
3533 // If force write is set, write the last file anyway, even though it didn't exist before:
36- return appendOrCreateFile ( paths . slice ( - 1 ) [ 0 ] , contents ) ;
34+ return fs . appendOrCreateFile ( paths . slice ( - 1 ) [ 0 ] , contents ) ;
3735 }
3836} ;
3937
@@ -196,19 +194,19 @@ export const editShellStartupScripts = async () => {
196194 [
197195 path . join ( os . homedir ( ) , '.config' , 'fish' , 'config.fish' ) ,
198196 ] ,
199- SHELL === 'fish' || await canAccess ( path . join ( os . homedir ( ) , '.config' , 'fish' ) ) ,
197+ SHELL === 'fish' || await fs . canAccess ( path . join ( os . homedir ( ) , '.config' , 'fish' ) ) ,
200198 FISH_SHELL_PATH_CONFIG
201199 ) . catch ( logError ) ;
202200} ;
203201
204202const removeConfigSectionsFromFile = async ( path : string ) => {
205203 let fileLines : string [ ] ;
206204
207- const targetPath = await getRealPath ( path ) ; // Follow symlinks, if present
205+ const targetPath = await fs . getRealPath ( path ) ; // Follow symlinks, if present
208206 if ( ! targetPath ) return ; // File doesn't exist, no need to clean it up
209207
210208 try {
211- fileLines = ( await readFile ( targetPath , 'utf8' ) ) . split ( '\n' ) ;
209+ fileLines = ( await fs . readFile ( targetPath , 'utf8' ) ) . split ( '\n' ) ;
212210 } catch ( e ) {
213211 // Silently skip any files we can't read
214212 return ;
@@ -227,8 +225,8 @@ const removeConfigSectionsFromFile = async (path: string) => {
227225 // Write & rename to ensure this is atomic, and avoid races here
228226 // as much as we reasonably can.
229227 const tempFile = targetPath + Date . now ( ) + '.temp' ;
230- await writeFile ( tempFile , fileLines . join ( '\n' ) ) ;
231- return moveFile ( tempFile , targetPath ) ;
228+ await fs . writeFile ( tempFile , fileLines . join ( '\n' ) ) ;
229+ return fs . moveFile ( tempFile , targetPath ) ;
232230} ;
233231
234232// Cleanup: strip our extra config line from all config files
0 commit comments