@ -342,17 +342,8 @@ vscode.workspace.onDidChangeConfiguration(async (e) => {
} ) ;
} ) ;
loadConfigs ( ) ;
loadConfigs ( ) ;
function parseFlagList ( list : string [ ] | undefined , origin : string ) : Record < string , FlagCombo > {
export type FlagValue = string | boolean | null ;
if ( list === undefined ) return { } ;
export type FlagCombo = [ value : FlagValue , origin : string ] ;
export const DEFAULT_FLAGS : string [ ] = [ '-DF-GE' ] ;
let cachedFlags : Record < string , FlagCombo > = { } ;
function calculateFlags ( ) : Record < string , FlagCombo > {
const flags : Record < string , FlagCombo > = { } ;
const config = vscode . workspace . getConfiguration ( 'sshfs' ) . inspect < string [ ] > ( 'flags' ) ;
if ( ! config ) throw new Error ( ` Could not inspect "sshfs.flags" config field ` ) ;
function parseList ( list : string [ ] | undefined , origin : string ) {
if ( list === undefined ) return ;
if ( ! Array . isArray ( list ) ) throw new Error ( ` Expected string array for flags, but got: ${ list } ` ) ;
if ( ! Array . isArray ( list ) ) throw new Error ( ` Expected string array for flags, but got: ${ list } ` ) ;
const scope : Record < string , FlagCombo > = { } ;
const scope : Record < string , FlagCombo > = { } ;
for ( const flag of list ) {
for ( const flag of list ) {
@ -373,19 +364,27 @@ function calculateFlags(): Record<string, FlagCombo> {
if ( name in scope ) continue ;
if ( name in scope ) continue ;
scope [ name ] = [ value , origin ] ;
scope [ name ] = [ value , origin ] ;
}
}
// Override if necessary (since workspace settings come after global settings)
return scope ;
// Per "location", we still ignore duplicate flag names
Object . assign ( flags , scope ) ;
}
}
parseList ( DEFAULT_FLAGS , 'Built-in Default' ) ;
parseList ( config . defaultValue , 'Default Settings' ) ;
export type FlagValue = string | boolean | null ;
export type FlagCombo = [ value : FlagValue , origin : string ] ;
export const DEFAULT_FLAGS : string [ ] = [ '-DF-GE' ] ;
let cachedFlags : Record < string , FlagCombo > = { } ;
function calculateFlags ( ) : Record < string , FlagCombo > {
const flags : Record < string , FlagCombo > = { } ;
const config = vscode . workspace . getConfiguration ( 'sshfs' ) . inspect < string [ ] > ( 'flags' ) ;
if ( ! config ) throw new Error ( ` Could not inspect "sshfs.flags" config field ` ) ;
const applyList = ( list : string [ ] | undefined , origin : string ) = > Object . assign ( flags , parseFlagList ( list , origin ) ) ;
applyList ( DEFAULT_FLAGS , 'Built-in Default' ) ;
applyList ( config . defaultValue , 'Default Settings' ) ;
// Electron v11 crashes for DiffieHellman GroupExchange, although it's fixed in 11.3.0
// Electron v11 crashes for DiffieHellman GroupExchange, although it's fixed in 11.3.0
if ( ( process . versions as { electron? : string } ) . electron ? . match ( /^11\.(0|1|2)\./ ) ) {
if ( ( process . versions as { electron? : string } ) . electron ? . match ( /^11\.(0|1|2)\./ ) ) {
parseList ( [ '+DF-GE' ] , 'Fix for issue #239' )
apply List( [ '+DF-GE' ] , 'Fix for issue #239' )
}
}
parseList ( config . globalValue , 'Global Settings' ) ;
apply List( config . globalValue , 'Global Settings' ) ;
parseList ( config . workspaceValue , 'Workspace Settings' ) ;
apply List( config . workspaceValue , 'Workspace Settings' ) ;
parseList ( config . workspaceFolderValue , 'WorkspaceFolder Settings' ) ;
apply List( config . workspaceFolderValue , 'WorkspaceFolder Settings' ) ;
Logging . info ( ` Calculated config flags: ${ JSON . stringify ( flags ) } ` ) ;
Logging . info ( ` Calculated config flags: ${ JSON . stringify ( flags ) } ` ) ;
return cachedFlags = flags ;
return cachedFlags = flags ;
}
}
@ -395,8 +394,17 @@ vscode.workspace.onDidChangeConfiguration(event => {
} ) ;
} ) ;
calculateFlags ( ) ;
calculateFlags ( ) ;
/** Returns a cached version. Gets updated by ConfigurationChangeEvent events */
/ * *
export function getFlags ( ) : Record < string , FlagCombo > { return cachedFlags ; }
* Returns ( a copy of the ) global flags . Gets updated by ConfigurationChangeEvent events .
* In case ` flags ` is given , flags specified in this array will override global ones in the returned result .
* @param flags An optional array of flags to check before the global ones
* /
export function getFlags ( flags? : string [ ] ) : Record < string , FlagCombo > {
return {
. . . cachedFlags ,
. . . parseFlagList ( flags , 'Override' ) ,
} ;
}
/ * *
/ * *
* Checks the ` sshfs.flags ` config ( overridable by e . g . workspace settings ) .
* Checks the ` sshfs.flags ` config ( overridable by e . g . workspace settings ) .
@ -411,9 +419,10 @@ export function getFlags(): Record<string, FlagCombo> { return cachedFlags; }
* For ` undefined ` , an actual ` undefined ` is returned . For all other cases , a FlagCombo
* For ` undefined ` , an actual ` undefined ` is returned . For all other cases , a FlagCombo
* is returned , e . g . "NAME" returns ` [null, "someOrigin"] ` and ` "+F" ` returns ` [true, "someOrigin"] `
* is returned , e . g . "NAME" returns ` [null, "someOrigin"] ` and ` "+F" ` returns ` [true, "someOrigin"] `
* @param target The name of the flag to look for
* @param target The name of the flag to look for
* @param flags An optional array of flags to check before the global ones
* /
* /
export function getFlag ( target : string ): FlagCombo | undefined {
export function getFlag ( target : string , flags? : string [ ] ): FlagCombo | undefined {
return calculateFlags( ) [ target . toLowerCase ( ) ] ;
return getFlags( flags ) [ target . toLowerCase ( ) ] ;
}
}
/ * *
/ * *
@ -428,10 +437,11 @@ export function getFlag(target: string): FlagCombo | undefined {
* - All other strings result in an error
* - All other strings result in an error
* @param target The name of the flag to look for
* @param target The name of the flag to look for
* @param defaultValue The value to return when no flag with the given name is present
* @param defaultValue The value to return when no flag with the given name is present
* @param flags An optional array of flags to check before the global ones
* @returns The matching FlagCombo or ` [missingValue, 'missing'] ` instead
* @returns The matching FlagCombo or ` [missingValue, 'missing'] ` instead
* /
* /
export function getFlagBoolean ( target : string , missingValue : boolean ): FlagCombo {
export function getFlagBoolean ( target : string , missingValue : boolean , flags? : string [ ] ): FlagCombo {
const combo = getFlag ( target );
const combo = getFlag ( target , flags );
if ( ! combo ) return [ missingValue , 'missing' ] ;
if ( ! combo ) return [ missingValue , 'missing' ] ;
const [ value , reason ] = combo ;
const [ value , reason ] = combo ;
if ( value == null ) return [ true , reason ] ;
if ( value == null ) return [ true , reason ] ;