[kbn-es] download to destPath.tmp rather than /tmp (#17322)

When kbn-es downloads a snapshot, it writes the in progress download to
`/tmp` rather than the destination path in case the download fails part
way through, then renames the file from `/tmp` to the final location.
This is a good practice, but in CI the `/tmp` directory isn't stored on
the same disk as the project, which causes a rename error to occur
because we're attempting to rename across devices.

This updates the download logic to write to `${destPath}.tmp` instead,
and do the same renaming, so that we can avoid cross-device errors.
This commit is contained in:
Spencer 2018-03-21 17:46:12 -07:00 committed by GitHub
parent 6bac181a74
commit 026d140aaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View file

@ -3,7 +3,7 @@ const fs = require('fs');
const mkdirp = require('mkdirp');
const chalk = require('chalk');
const path = require('path');
const { BASE_PATH, DL_PATH } = require('../paths');
const { BASE_PATH } = require('../paths');
const { installArchive } = require('./archive');
const { log: defaultLog, cache } = require('../utils');
@ -40,10 +40,10 @@ exports.installSnapshot = async function installSnapshot({
* @returns {Promose}
*/
function downloadFile(url, dest, log) {
const downloadPath = path.resolve(DL_PATH, path.basename(dest));
const downloadPath = `${dest}.tmp`;
const cacheMeta = cache.readMeta(dest);
mkdirp.sync(DL_PATH);
mkdirp.sync(path.dirname(dest));
log.info('downloading from %s', chalk.bold(url));

View file

@ -8,7 +8,6 @@ function useBat(bin) {
const tempDir = os.tmpdir();
exports.BASE_PATH = path.resolve(tempDir, 'kbn-es');
exports.DL_PATH = tempDir;
exports.GRADLE_BIN = useBat('./gradlew');
exports.ES_BIN = useBat('bin/elasticsearch');