MCPcopy Create free account
hub / github.com/apache/camel-website / fetchFromNetwork

Method fetchFromNetwork

github-release-binary.js:100–163  ·  view source on GitHub ↗
(locator, opts)

Source from the content-addressed store, hash-verified

98 }
99
100 async fetchFromNetwork(locator, opts) {
101 // 1980-01-01, like Fedora
102 const defaultTime = 315532800;
103
104 const parts = parse(locator.reference);
105
106 const releaseBuffer = await httpUtils.get(`https://github.com/${parts.organization}/${parts.repository}/releases/download/${parts.version}/${parts.binary}`, {
107 configuration: opts.project.configuration,
108 });
109
110 const packageName = ppath.join(locator.scope !== null ? '@' + locator.scope : '', locator.name);
111
112 const tmpDir = xfs.mktempSync();
113
114 const zipFS = new ZipFS(ppath.join(tmpDir, 'release.zip'), { create: true, libzip: await getLibzipPromise() });
115
116 zipFS.writeFileSync('package.json', `{ "name": "${packageName}", "dependencies": { "@yarnpkg/fslib": "${YARN_FS_VERSION}" } }`);
117 zipFS.utimesSync('package.json', defaultTime, defaultTime);
118
119 const dir = ppath.join('node_modules', packageName);
120 zipFS.mkdirSync(dir, { recursive: true });
121
122 const stubFile = ppath.join(dir, 'exec.js');
123 zipFS.writeFileSync(stubFile, `const { xfs } = require('@yarnpkg/fslib');
124const fs = require('fs');
125const path = require('path');
126const os = require('os');
127const { spawn } = require('child_process');
128
129const execute = (path, args) => {
130 const child = spawn(path, args);
131
132 process.stdin.pipe(child.stdin);
133 child.stdout.pipe(process.stdout);
134 child.stderr.pipe(process.stderr);
135
136 child.on('error', err => { process.stderr.write(err + '\\n'); process.exit(1) } );
137 child.on('exit', status => process.exit(status));
138}
139
140(async () => {
141 const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'github-release-binary'));
142 process.on('exit', () => {
143 fs.rmdirSync(tmpDir, { recursive: true });
144 })
145
146 const binary = process.argv[1].replace('exec.js', '${parts.binary}');
147 const binaryPath = path.join(tmpDir, '${parts.binary}');
148 await xfs.copyFilePromise(binary, binaryPath);
149 await xfs.chmodPromise(binaryPath, 0o755);
150 execute(binaryPath, process.argv.slice(2));
151})();`);
152 zipFS.chmodSync(stubFile, 0o755);
153 zipFS.utimesSync(stubFile, defaultTime, defaultTime);
154
155 const binaryPath = ppath.join(dir, parts.binary);
156 zipFS.writeFileSync(binaryPath, releaseBuffer);
157 zipFS.chmodSync(binaryPath, 0o755);

Callers 1

fetchMethod · 0.95

Calls 1

parseFunction · 0.85

Tested by

no test coverage detected