Fix homedir

This commit is contained in:
CrazyMax 2020-05-04 16:32:30 +02:00
parent 95b2df2352
commit c263b24136
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
2 changed files with 12 additions and 4 deletions

7
dist/index.js generated vendored
View file

@ -1110,7 +1110,7 @@ const fs = __importStar(__webpack_require__(747));
const path = __importStar(__webpack_require__(622)); const path = __importStar(__webpack_require__(622));
const os = __importStar(__webpack_require__(87)); const os = __importStar(__webpack_require__(87));
const exec = __importStar(__webpack_require__(807)); const exec = __importStar(__webpack_require__(807));
exports.agentConfig = `default-cache-ttl 1 exports.agentConfig = `default-cache-ttl 7200
max-cache-ttl 31536000 max-cache-ttl 31536000
allow-preset-passphrase`; allow-preset-passphrase`;
exports.getVersion = () => __awaiter(void 0, void 0, void 0, function* () { exports.getVersion = () => __awaiter(void 0, void 0, void 0, function* () {
@ -1199,7 +1199,10 @@ exports.getKeygrip = (fingerprint) => __awaiter(void 0, void 0, void 0, function
}); });
}); });
exports.configureAgent = (config) => __awaiter(void 0, void 0, void 0, function* () { exports.configureAgent = (config) => __awaiter(void 0, void 0, void 0, function* () {
const { homedir: homedir } = yield exports.getDirs(); let homedir = path.join(process.env.HOME || '', '.gnupg');
if (os.platform() == 'win32') {
homedir = path.join(process.env.USERPROFILE || '', '.gnupg');
}
const gpgAgentConf = path.join(homedir, 'gpg-agent.conf'); const gpgAgentConf = path.join(homedir, 'gpg-agent.conf');
yield fs.writeFile(gpgAgentConf, config, function (err) { yield fs.writeFile(gpgAgentConf, config, function (err) {
if (err) if (err)

View file

@ -3,7 +3,7 @@ import * as path from 'path';
import * as os from 'os'; import * as os from 'os';
import * as exec from './exec'; import * as exec from './exec';
export const agentConfig = `default-cache-ttl 1 export const agentConfig = `default-cache-ttl 7200
max-cache-ttl 31536000 max-cache-ttl 31536000
allow-preset-passphrase`; allow-preset-passphrase`;
@ -111,11 +111,16 @@ export const getKeygrip = async (fingerprint: string): Promise<string> => {
}; };
export const configureAgent = async (config: string): Promise<void> => { export const configureAgent = async (config: string): Promise<void> => {
const {homedir: homedir} = await getDirs(); let homedir: string = path.join(process.env.HOME || '', '.gnupg');
if (os.platform() == 'win32') {
homedir = path.join(process.env.USERPROFILE || '', '.gnupg');
}
const gpgAgentConf = path.join(homedir, 'gpg-agent.conf'); const gpgAgentConf = path.join(homedir, 'gpg-agent.conf');
await fs.writeFile(gpgAgentConf, config, function (err) { await fs.writeFile(gpgAgentConf, config, function (err) {
if (err) throw err; if (err) throw err;
}); });
await exec.exec(`gpg-connect-agent "RELOADAGENT" /bye`, [], true).then(res => { await exec.exec(`gpg-connect-agent "RELOADAGENT" /bye`, [], true).then(res => {
if (res.stderr != '' && !res.success) { if (res.stderr != '' && !res.success) {
throw new Error(res.stderr); throw new Error(res.stderr);