Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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();
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));
}
});
});
};
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));
}
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)
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))));
}
});
});
};
private async doWithPreferenceFile(withPreferenceFile: WithPreferenceFile): Promise {
await lock(this.filePath, { retries: 5 });
const prefs = await this.read();
let result;
try {
result = await withPreferenceFile(prefs);
if (result.save) {
await fs.writeJson(this.filePath, prefs);
}
} catch (e) {
logger.error(`Operation on preference file failed: ${e.message}`);
}
await unlock(this.filePath);
return result.value as V;
}
setItem(key, value, cb) {
lockfile.lock(this.path, this._lockfileOptions(), (err, release) => {
if (err) {
return cb(err);
}
cb = this._releaseAndCb(release, cb);
this._getData((err, data) => {
if (err) {
return cb(err);
}
data[key] = value;
this._writeData(data, (err) => cb(err));
});
});
}