This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 410
Expand file tree
/
Copy pathgit-temp-dir.js
More file actions
81 lines (67 loc) · 1.78 KB
/
git-temp-dir.js
File metadata and controls
81 lines (67 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os from 'os';
import path from 'path';
import fs from 'fs-extra';
import {getPackageRoot, getTempDir} from './helpers';
export const BIN_SCRIPTS = {
getCredentialHelperJs: 'git-credential-atom.js',
getCredentialHelperSh: 'git-credential-atom.sh',
getAskPassJs: 'git-askpass-atom.js',
getAskPassSh: 'git-askpass-atom.sh',
getSshWrapperSh: 'linux-ssh-wrapper.sh',
getGpgWrapperSh: 'gpg-wrapper.sh',
};
export default class GitTempDir {
constructor() {
this.created = false;
}
async ensure() {
if (this.created) {
return;
}
this.root = await getTempDir({
dir: process.platform === 'win32' ? os.tmpdir() : '/tmp',
prefix: 'github-',
symlinkOk: true,
});
await Promise.all(
Object.values(BIN_SCRIPTS).map(async filename => {
await fs.copy(
path.resolve(getPackageRoot(), 'bin', filename),
path.join(this.root, filename),
);
if (path.extname(filename) === '.sh') {
await fs.chmod(path.join(this.root, filename), 0o700);
}
}),
);
this.created = true;
}
getRootPath() {
return this.root;
}
getScriptPath(filename) {
if (!this.created) {
throw new Error(`Attempt to access filename ${filename} in uninitialized GitTempDir`);
}
return path.join(this.root, filename);
}
getSocketOptions() {
if (process.platform === 'win32') {
return {port: 0, host: 'localhost'};
} else {
return {path: this.getScriptPath('helper.sock')};
}
}
dispose() {
return fs.remove(this.root);
}
}
function createGetter(key) {
const filename = BIN_SCRIPTS[key];
return function() {
return this.getScriptPath(filename);
};
}
for (const key in BIN_SCRIPTS) {
GitTempDir.prototype[key] = createGetter(key);
}