How to use proper-lockfile - 10 common examples

To help you get started, we’ve selected a few proper-lockfile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vesparny / borgjs / lib / cli.js View on Github external
if (!config.repository) {
  console.log(
    chalk.red('The "repository" option must be specified in the config file')
  )
  process.exit(1)
}
const fileLock = path.join(
  osTmpdir(),
  filenamify(config.repository, { replacement: '-' })
)
// ensure the dir exists, otherwise it's impossible to acquire the lock
if (!fs.existsSync(fileLock)) {
  fs.mkdirSync(fileLock)
}
if (fs.existsSync(`${fileLock}.lock`)) {
  if (lockfile.checkSync(fileLock)) {
    console.log(
      chalk.cyan(
        `
      There is probably another borgjs runnign process.
      The look file seems to be locked.

      ${chalk.yellow(fileLock + '.lock')}
    `
      )
    )
    process.exit(1)
  }
}
lockfile.lock(fileLock, err => {
  if (err) {
    console.log(chalk.red(err.message))
github vesparny / borgjs / bin / index.js View on Github external
if (!config.repository) {
  console.log(
    chalk.red('The "repository" option must be specified in the config file')
  )
  process.exit(1)
}
const fileLock = path.join(
  osTmpdir(),
  filenamify(config.repository, { replacement: '-' })
)
// ensure the dir exists, otherwise it's impossible to acquire the lock
if (!fs.existsSync(fileLock)) {
  fs.mkdirSync(fileLock)
}
if (fs.existsSync(`${fileLock}.lock`)) {
  if (lockfile.checkSync(fileLock)) {
    console.log(
      chalk.cyan(
        `
      lockfile detected.
      There is probably another borgjs runnign process.

      ${chalk.yellow(fileLock + '.lock')}
    `
      )
    )
    process.exit(1)
  }
}
lockfile.lock(fileLock, err => {
  if (err) {
    console.log(chalk.red(err.message))
github elastic / kibana / x-pack / plugins / code / server / lsp / workspace_command.ts View on Github external
public async runInit(force: boolean) {
    if (this.repoConfig.init) {
      const versionFile = path.join(this.workspaceDir, 'init.version');
      if (this.checkRevision(versionFile) && !force) {
        this.log.info('a same revision exists, init cmd skipped.');
        return;
      }
      const lockFile = this.workspaceDir; // path.join(this.workspaceDir, 'init.lock');

      const isLocked = await LockFile.check(lockFile);
      if (isLocked) {
        this.log.info('another process is running, please try again later');
        return;
      }
      const release = await LockFile.lock(lockFile);

      try {
        const process = this.spawnProcess(this.repoConfig.init);
        const logFile = path.join(this.workspaceDir, 'init.log');
        const logFileStream = fs.createWriteStream(logFile, { encoding: 'utf-8', flags: 'a+' });
        this.redirectOutput(process.stdout, logFileStream);
        this.redirectOutput(process.stderr, logFileStream, true);
        process.on('close', async (code, signal) => {
          logFileStream.close();
          await this.writeRevisionFile(versionFile);
          this.log.info(`init process finished with code: ${code} signal: ${signal}`);
          await release();
        });
      } catch (e) {
        this.log.error(e);
        release();
github fulcrumapp / fulcrum-desktop / resources / yarn / yarn / lib-legacy / cli / index.js View on Github external
return new (_promise || _load_promise()).default(ok => {
    const lockFilename = mutexFilename || path.join(config.cwd, (_constants || _load_constants()).SINGLE_INSTANCE_FILENAME);
    lockfile.lock(lockFilename, { realpath: false }, (err, release) => {
      if (err) {
        if (isFirstTime) {
          reporter.warn(reporter.lang('waitingInstance'));
        }
        setTimeout(() => {
          ok(runEventuallyWithFile(mutexFilename, isFirstTime));
        }, 200); // do not starve the CPU
      } else {
        onDeath(() => {
          process.exit(1);
        });
        ok(run().then(release));
      }
    });
  });
};
github elastic / kibana / x-pack / legacy / plugins / code / server / lsp / workspace_command.ts View on Github external
public async runInit(force: boolean) {
    if (this.repoConfig.init) {
      const versionFile = path.join(this.workspaceDir, 'init.version');
      if (this.checkRevision(versionFile) && !force) {
        this.log.info('a same revision exists, init cmd skipped.');
        return;
      }
      const lockFile = this.workspaceDir; // path.join(this.workspaceDir, 'init.lock');

      const isLocked = await LockFile.check(lockFile);
      if (isLocked) {
        this.log.info('another process is running, please try again later');
        return;
      }
      const release = await LockFile.lock(lockFile);

      try {
        if (!this.repoConfig.hasOwnProperty('init')) {
          throw new Error(
            `RepoConfig's init comes from a prototype, this is unexpected and unsupported`
          );
        }
        const process = this.spawnProcess(this.repoConfig.init);
        const logFile = path.join(this.workspaceDir, 'init.log');
        const logFileStream = fs.createWriteStream(logFile, { encoding: 'utf-8', flags: 'a+' });
        this.redirectOutput(process.stdout, logFileStream);
github elastic / kibana / kibana-extra / code / server / lsp / workspace_command.ts View on Github external
public async runInit(force: boolean) {
    if (this.repoConfig.init) {
      const versionFile = path.join(this.workspaceDir, 'init.version');
      if (this.checkRevision(versionFile) && !force) {
        this.log.info('a same revision exists, init cmd skipped.');
        return;
      }
      const lockFile = this.workspaceDir; // path.join(this.workspaceDir, 'init.lock');

      const isLocked = await LockFile.check(lockFile);
      if (isLocked) {
        this.log.info('another process is running, please try again later');
        return;
      }
      const release = await LockFile.lock(lockFile);

      try {
        const process = this.spawnProcess(this.repoConfig.init);
        const logFile = path.join(this.workspaceDir, 'init.log');
        const logFileStream = fs.createWriteStream(logFile, { encoding: 'utf-8', flags: 'a+' });
        this.redirectOutput(process.stdout, logFileStream);
        this.redirectOutput(process.stderr, logFileStream, true);
        process.on('close', async (code, signal) => {
          logFileStream.close();
          await this.writeRevisionFile(versionFile);
          this.log.info(`init process finished with code: ${code} signal: ${signal}`);
github elastic / kibana / x-pack / plugins / code / server / lsp / workspace_command.ts View on Github external
public async runInit(force: boolean) {
    if (this.repoConfig.init) {
      const versionFile = path.join(this.workspaceDir, 'init.version');
      if (this.checkRevision(versionFile) && !force) {
        this.log.info('a same revision exists, init cmd skipped.');
        return;
      }
      const lockFile = this.workspaceDir; // path.join(this.workspaceDir, 'init.lock');

      const isLocked = await LockFile.check(lockFile);
      if (isLocked) {
        this.log.info('another process is running, please try again later');
        return;
      }
      const release = await LockFile.lock(lockFile);

      try {
        const process = this.spawnProcess(this.repoConfig.init);
        const logFile = path.join(this.workspaceDir, 'init.log');
        const logFileStream = fs.createWriteStream(logFile, { encoding: 'utf-8', flags: 'a+' });
        this.redirectOutput(process.stdout, logFileStream);
        this.redirectOutput(process.stderr, logFileStream, true);
        process.on('close', async (code, signal) => {
          logFileStream.close();
          await this.writeRevisionFile(versionFile);
          this.log.info(`init process finished with code: ${code} signal: ${signal}`);
github esy / esy / esy-install / src / bin / runYarnCommand.js View on Github external
return new Promise(resolve => {
      const lockFilename =
        mutexFilename || path.join(config.cwd, constants.SINGLE_INSTANCE_FILENAME);
      lockfile.lock(
        lockFilename,
        {realpath: false},
        (err: mixed, release: () => void) => {
          if (err) {
            if (isFirstTime) {
              ctx.reporter.warn(ctx.reporter.lang('waitingInstance'));
            }
            setTimeout(() => {
              resolve(runEventuallyWithFile(mutexFilename, false));
            }, 200); // do not starve the CPU
          } else {
            onDeath(() => {
              process.exitCode = 1;
            });
            resolve(run().then(release));
          }
github LinusU / vscode-auto-dark-mode / index.js View on Github external
async function switchTheme (target) {
  const lockfile = require('proper-lockfile')

  let release
  try {
    release = await lockfile.lock('', { lockfilePath })
  } catch (err) {
    if (err.code === 'ELOCKED') {
      // Another
      return
    }

    throw err
  }

  try {
    const colorTheme = workspace.getConfiguration('autoDarkMode').get(`${target}Theme`)
    workspace.getConfiguration('workbench').update('colorTheme', colorTheme, ConfigurationTarget.Global)

    const iconTheme = workspace.getConfiguration('autoDarkMode').get(`${target}IconTheme`)
    if (iconTheme) {
      workspace.getConfiguration('workbench').update('iconTheme', iconTheme, ConfigurationTarget.Global)
github yarnpkg / yarn / src / cli / index.js View on Github external
return new Promise(resolve => {
      const lockFilename = mutexFilename || path.join(config.cwd, constants.SINGLE_INSTANCE_FILENAME);
      lockfile.lock(lockFilename, {realpath: false}, (err: mixed, release: (() => void) => void) => {
        if (err) {
          if (isFirstTime) {
            reporter.warn(reporter.lang('waitingInstance'));
          }
          setTimeout(() => {
            resolve(runEventuallyWithFile(mutexFilename, false));
          }, 200); // do not starve the CPU
        } else {
          onDeath(() => {
            process.exitCode = 1;
          });
          resolve(run().then(() => new Promise(resolve => release(resolve))));
        }
      });
    });
  };

proper-lockfile

A inter-process and inter-machine lockfile utility that works on a local or network file system

MIT
Latest version published 3 years ago

Package Health Score

74 / 100
Full package analysis