<commit_before>const upath = require('upath');
const process = require('process');
const fs = require('fs-extra');
const { exec } = require('child-process-promise');
const { getChildProcessEnv } = require('../../util/env');
const { logger } = require('../../logger');

module.exports = {
  updateArtifacts,
};

async function updateArtifacts(
  packageFileName,
  updatedDeps,
  newPackageFileContent,
  config
) {
  await logger.debug(`cargo.updateArtifacts(${packageFileName})`);
  if (updatedDeps === undefined || updatedDeps.length < 1) {
    logger.debug('No updated cargo deps - returning null');
    return null;
  }
  const lockFileName = 'Cargo.lock';
  const existingLockFileContent = await platform.getFile(lockFileName);
  if (!existingLockFileContent) {
    logger.debug('No Cargo.lock found');
    return null;
  }
  const localPackageFileName = upath.join(config.localDir, packageFileName);
  const localLockFileName = upath.join(config.localDir, lockFileName);
  let stdout;
  let stderr;
  try {
    await fs.outputFile(localPackageFileName, newPackageFileContent);
    logger.debug('Updating ' + lockFileName);
    const cwd = config.localDir;
    const env = getChildProcessEnv();
    for (let i = 0; i < updatedDeps.length; i += 1) {
      const dep = updatedDeps[i];
      // Update dependency `${dep}` in Cargo.lock file corresponding to Cargo.toml file located
      // at ${localPackageFileName} path
      let cmd;
      // istanbul ignore if
      if (config.binarySource === 'docker') {
        logger.info('Running cargo via docker');
        cmd = `docker run --rm `;
        const volumes = [cwd];
        cmd += volumes.map(v => `-v ${v}:${v} `).join('');
        const envVars = [];
        cmd += envVars.map(e => `-e ${e} `);
        cmd += `-w ${cwd} `;
        cmd += `renovate/rust cargo`;
      } else {
        logger.info('Running cargo via global cargo');
        cmd = 'cargo';
      }
      cmd += ` update --manifest-path ${localPackageFileName} --package ${dep}`;
      const startTime = process.hrtime();
      try {
        ({ stdout, stderr } = await exec(cmd, {
          cwd,
          shell: true,
          env,<commit_msg>chore: cargo envVars map join<commit_after>const upath = require('upath');
const process = require('process');
const fs = require('fs-extra');
const { exec } = require('child-process-promise');
const { getChildProcessEnv } = require('../../util/env');
const { logger } = require('../../logger');

module.exports = {
  updateArtifacts,
};

async function updateArtifacts(
  packageFileName,
  updatedDeps,
  newPackageFileContent,
  config
) {
  await logger.debug(`cargo.updateArtifacts(${packageFileName})`);
  if (updatedDeps === undefined || updatedDeps.length < 1) {
    logger.debug('No updated cargo deps - returning null');
    return null;
  }
  const lockFileName = 'Cargo.lock';
  const existingLockFileContent = await platform.getFile(lockFileName);
  if (!existingLockFileContent) {
    logger.debug('No Cargo.lock found');
    return null;
  }
  const localPackageFileName = upath.join(config.localDir, packageFileName);
  const localLockFileName = upath.join(config.localDir, lockFileName);
  let stdout;
  let stderr;
  try {
    await fs.outputFile(localPackageFileName, newPackageFileContent);
    logger.debug('Updating ' + lockFileName);
    const cwd = config.localDir;
    const env = getChildProcessEnv();
    for (let i = 0; i < updatedDeps.length; i += 1) {
      const dep = updatedDeps[i];
      // Update dependency `${dep}` in Cargo.lock file corresponding to Cargo.toml file located
      // at ${localPackageFileName} path
      let cmd;
      // istanbul ignore if
      if (config.binarySource === 'docker') {
        logger.info('Running cargo via docker');
        cmd = `docker run --rm `;
        const volumes = [cwd];
        cmd += volumes.map(v => `-v ${v}:${v} `).join('');
        const envVars = [];
        cmd += envVars.map(e => `-e ${e} `).join('');
        cmd += `-w ${cwd} `;
        cmd += `renovate/rust cargo`;
      } else {
        logger.info('Running cargo via global cargo');
        cmd = 'cargo';
      }
      cmd += ` update --manifest-path ${localPackageFileName} --package ${dep}`;
      const startTime = process.hrtime();
      try {
        ({ stdout, stderr } = await exec(cmd, {
          cwd,
          shell: true,
          env,
{'fraction_non_alphanumeric': 0.14857142857142858, 'fraction_numerical': 0.0013714285714285714, 'mean_word_length': 2.949458483754513, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6319895', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1321, 'n_words': 338}