Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fs.access(outputDir, error => {
if (error) {
if (error.code === "ENOENT" || error.code === "ENOTDIR") {
// ENOENT or ENOTDIR are to be expected when we haven't yet
// fetched a package for the first time. Carry on!
mkdirp.sync(outputDir);
const release = lockfile.lockSync(outputDir);
fetchPackage(tarballURL, outputDir).then(
() => {
release();
callback(null, outputDir);
},
error => {
release();
callback(error);
}
);
} else {
callback(error);
}
} else {
lockfile.check(outputDir).then(locked => {
constructor(opts: Options) {
this.opts = opts
this.path = opts.path || 'default'
// initialize storage
if (!opts.memory) {
ensureDirectoryExists(this.path)
// Attempt to acquite a lock on the repo to prevent concurrent corrupting access.
this.lockRelease = lockfile.lockSync(this.path)
}
this.storage = opts.memory ? ram : raf
this.db = SqlDatabase.open(path.resolve(this.path, 'hypermerge.db'), opts.memory || false)
this.keys = new KeyStore(this.db)
this.feeds = new FeedStore(this.db, (path: string) => this.storageFn('feeds/' + path))
this.files = new FileStore(this.feeds)
// init repo
const repoKeys = this.keys.get('self.repo') || this.keys.set('self.repo', Keys.createBuffer())
this.swarmKey = repoKeys.publicKey
this.id = encodeRepoId(repoKeys.publicKey)
// initialize the various stores
this.cursors = new CursorStore(this.db)
this.clocks = new ClockStore(this.db)
writeSync() {
let output = JSON.stringify(this._data, null, 2);
let release = lockfile.lockSync(this.configFile, { realpath: false });
fs.writeFileSync(this.configFile, output);
release();
}
lock(symlink = true) {
try {
this._unlock = lockfile.lockSync(this.fileName, symlink ? undefined : { realpath: false });
this.locked = true;
}
catch (e) {
if (symlink && e.code === 'ENOENT')
return this.lock(false);
if (e.code === 'ELOCKED')
throw new common_1.JspmUserError(`Configuration file ${common_1.bold(this.fileName)} is currently locked by another jspm process.`);
throw e;
}
}
unlock() {
GlobalConfigFile.prototype.lock = function() {
if (!this._unlock) {
try {
this._unlock = lockFile.lockSync(this.globalConfigFile, {
retries: {
retries: 10,
minTimeout: 20,
maxTimeout: 300,
randomize: true
},
realpath: false
});
} catch (e) {
if (e.code === 'ELOCKED')
throw 'Unable to lock global config file %' + this.globalConfigFile + '%, not overwriting';
}
}
};
GlobalConfigFile.prototype.unlock = function() {