@@ -20,17 +20,6 @@ export interface Dirs {
2020 homedir : string ;
2121}
2222
23- const getGnupgHome = async ( ) : Promise < string > => {
24- if ( process . env . GNUPGHOME ) {
25- return process . env . GNUPGHOME ;
26- }
27- let homedir : string = path . join ( process . env . HOME || '' , '.gnupg' ) ;
28- if ( os . platform ( ) == 'win32' && ! process . env . HOME ) {
29- homedir = path . join ( process . env . USERPROFILE || '' , '.gnupg' ) ;
30- }
31- return homedir ;
32- } ;
33-
3423const gpgConnectAgent = async ( command : string ) : Promise < string > => {
3524 return await exec
3625 . getExecOutput ( `gpg-connect-agent "${ command } " /bye` , [ ] , {
@@ -50,6 +39,26 @@ const gpgConnectAgent = async (command: string): Promise<string> => {
5039 } ) ;
5140} ;
5241
42+ export const getHome = async ( ) : Promise < string > => {
43+ let homedir = '' ;
44+ if ( process . env . GNUPGHOME ) {
45+ homedir = process . env . GNUPGHOME ;
46+ } else if ( os . platform ( ) == 'win32' && ! process . env . HOME && process . env . USERPROFILE ) {
47+ homedir = path . join ( process . env . USERPROFILE , '.gnupg' ) ;
48+ } else if ( process . env . HOME ) {
49+ homedir = path . join ( process . env . HOME , '.gnupg' ) ;
50+ } else {
51+ homedir = ( await getDirs ( ) ) . homedir ;
52+ }
53+ if ( homedir . length == 0 ) {
54+ throw new Error ( 'Unable to determine GnuPG home directory' ) ;
55+ }
56+ if ( ! fs . existsSync ( homedir ) ) {
57+ fs . mkdirSync ( homedir , { recursive : true } ) ;
58+ }
59+ return homedir ;
60+ } ;
61+
5362export const getVersion = async ( ) : Promise < Version > => {
5463 return await exec
5564 . getExecOutput ( 'gpg' , [ '--version' ] , {
@@ -192,12 +201,8 @@ export const getKeygrip = async (fingerprint: string): Promise<string> => {
192201 } ) ;
193202} ;
194203
195- export const configureAgent = async ( config : string ) : Promise < void > => {
196- const gnupgHomeDir = await getGnupgHome ( ) ;
197- if ( ! fs . existsSync ( gnupgHomeDir ) ) {
198- fs . mkdirSync ( gnupgHomeDir , { recursive : true } ) ;
199- }
200- const gpgAgentConf = path . join ( gnupgHomeDir , 'gpg-agent.conf' ) ;
204+ export const configureAgent = async ( homedir : string , config : string ) : Promise < void > => {
205+ const gpgAgentConf = path . join ( homedir , 'gpg-agent.conf' ) ;
201206 await fs . writeFile ( gpgAgentConf , config , function ( err ) {
202207 if ( err ) throw err ;
203208 } ) ;
0 commit comments