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 {
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);
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}`);
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}`);
fetchPackage(tarballURL, outputDir).then(
() => {
release();
callback(null, outputDir);
},
error => {
release();
callback(error);
}
);
} else {
callback(error);
}
} else {
lockfile.check(outputDir).then(locked => {
if (locked) {
// Another process on this same machine has locked the
// directory. We need to wait for it to be unlocked
// before we callback.
const timer = setInterval(() => {
lockfile.check(outputDir).then(
locked => {
if (!locked) {
clearInterval(timer);
callback(null, outputDir);
}
},
error => {
clearInterval(timer);
callback(error);
}
const locked = await new Promise((resolve, reject) => lockfile.check(resolved, { realpath: false }, (err, locked) => err ? reject(err) : resolve(locked)));
if (locked)
return new Promise((resolve, reject) => {
locker.check(filePath, (error, isLocked) => {
if (error) {
reject(error);
return;
}
resolve(isLocked);
});
});
}
export async function lock ({ id, dir, root, options }) {
const lockPath = await getLockPath({ id, dir, root })
try {
const locked = await properlock.check(lockPath)
if (locked) {
consola.fatal(`A lock with id '${id}' already exists on ${dir}`)
}
} catch (e) {
consola.debug(`Check for an existing lock with id '${id}' on ${dir} failed`, e)
}
let lockWasCompromised = false
let release
try {
options = getLockOptions(options)
const onCompromised = options.onCompromised
options.onCompromised = (err) => {
onCompromised(err)
const timer = setInterval(() => {
lockfile.check(outputDir).then(
locked => {
if (!locked) {
clearInterval(timer);
callback(null, outputDir);
}
},
error => {
clearInterval(timer);
callback(error);
}
);
}, 10);