Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy values example candidates #19

Open
filipeom opened this issue Nov 7, 2024 · 1 comment
Open

Lazy values example candidates #19

filipeom opened this issue Nov 7, 2024 · 1 comment

Comments

@filipeom
Copy link
Member

filipeom commented Nov 7, 2024

  • vulcan-dataset/CWE-78/1512
var _, child_process, utils;

_ = require('lodash');

child_process = require('child_process');

utils = require('./utils');


/**
 * @summary Unmount a device
 * @public
 * @function
 *
 * @description
 * It does nothing for Windows.
 *
 * @param {String} device - device path
 * @param {Function} callback - callback (error, stdout, stderr)
 *
 * @example
 * umount.umount '/dev/disk2', (error, stdout, stderr) ->
 *		throw error if error?
 */

exports.umount = function(device, callback) {
  var unmountCommand;
  if (device == null) {
    throw new Error('Missing device');
  }
  if (!_.isString(device)) {
    throw new Error("Invalid device: " + device);
  }
  if (callback == null) {
    throw new Error('Missing callback');
  }
  if (!_.isFunction(callback)) {
    throw new Error("Invalid callback: " + callback);
  }
  if (utils.isWin32()) {
    return callback(null, null, null);
  }
  if (utils.isMacOSX()) {
    unmountCommand = '/usr/sbin/diskutil unmountDisk force';
  } else {
    unmountCommand = 'umount';
  }
  device = "\"" + device + "\"";
  if (utils.isLinux()) {
    device += '?* 2>/dev/null || /bin/true';
  }
  return child_process.exec(unmountCommand + " " + device, callback);
};
@filipeom
Copy link
Member Author

filipeom commented Nov 7, 2024

'use strict';

const { blue, bold, green, red } = require('chalk');
const path = require('path');
const semver = require('semver');
const { exec } = require('child_process');
const { promisify } = require('util');

const execAsync = promisify(exec);

async function getLatestVersions(name) {
  const { stdout } = await execAsync(`npm view ${name} versions --json`);
  try {
    return JSON.parse(stdout);
  } catch (err) {
    throw new Error(`Failed to parse output from NPM view - ${err.toString()}`);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant