writeLockInfo: function (data) { try { var fd = fs.openSync(data.path, 'w'); fs.writeSync(fd, JSON.stringify({ user: this.getCurrentUser(), pid: process.pid, tasks: grunt.cli.tasks, created: grunt.template.today('yyyy-mm-dd HH:MM:ss') })); } catch (ex) { //could not write infos to lockfile. I dont know what can cause this try { lockFile.unlockSync(data.path); grunt.fail.warn('Could not write info to lockfile'); } catch (ex2) { grunt.fail.warn('Could not write info to lockfile. Caution: Lockfile still exists!'); } } },
const loadExamples = async () => { await lockPromise(examples_lock, examples_lock_opts) if (!fs.existsSync('tests/data/bids-examples-' + test_version + '/')) { console.log('downloading test data') const response = request( 'GET', 'http://github.com/bids-standard/bids-examples/archive/' + test_version + '.zip', ) if (!fs.existsSync('bids-validator/tests/data')) { fs.mkdirSync('bids-validator/tests/data') } fs.writeFileSync('bids-validator/tests/data/examples.zip', response.body) const zip = new AdmZip('bids-validator/tests/data/examples.zip') console.log('unzipping test data') zip.extractAllTo('bids-validator/tests/data/', true) } lockfile.unlockSync(examples_lock) return test_version }
const done = () => { lockfile.unlockSync('db-file.lock'); };
}).finally(function () { lockFile.unlockSync(pkgLock); });
exports.unlock = function(lockName) { lockfile.unlockSync(lockName); };
grunt.registerTask('unlock', function(){ lockFile.unlockSync(LOCKFILE); });
process.on('exit', function() { lockFile.unlockSync(global.lockfile); logger.info('Indexer:: The indexer has finished running in %ssec', (new Date().getTime() - time) / 1000); });
proc.blocks.forEach(function (block) { console.log('-----'); console.log("Processing block for " + block.dest); var platform = require('os').platform(); var prefix = (platform === 'win32') ? 'node ' : ''; if(block.type=='css') { try{ console.log("Concatenating CSS"); var concatenatedCss = ''; //Concatenate CSS file contents block.src.forEach(function (css){ var fs = require("fs"); concatenatedCss += fs.readFileSync(css).toString(); }); console.log("Minifying CSS"); //Minify using clean-css var minimized = cleanCSS.process(concatenatedCss); fs.writeFileSync(block.dest, minimized); } catch(e){ console.log("ERROR while minifying CSS: "); console.log(e); return; } } else { try{ console.log("Minifying JS"); var uglify = require("uglify-js"); var uglified = uglify.minify(block.src, {compress:false}); fs.writeFileSync(block.dest, uglified.code); } catch(e){ console.log("ERROR while minifying JS: "); console.log(e); return; } } try{ var fileContents = fs.readFileSync(block.dest, {encoding:'utf8'}); console.log("Getting hash of file"); var hash = crypto.createHash('md5').update(fileContents).digest("hex"); var revPath = (path.join(path.dirname(block.dest), hash.substr(0, 8) + '.' + path.basename(block.dest))); console.log("Creating copy with hashed filename"); fs.createReadStream(block.dest).pipe(fs.createWriteStream(revPath)); } catch(e){ console.log("ERROR while hashing: "); console.log(e); return; } try{ var blockLine = block.raw.join(proc.linefeed); var replacement = blockLine.replace(blockLine, proc.replaceWith(block)); replacement = replacement.replace(path.basename(block.relativeDest), path.basename(revPath)); console.log('New reference: ' + replacement); lockFile.lockSync('lockfile.lock', {retries:10}); if(sourceHtml.length <= 0){ console.log("ERROR reading " + options.htmlFile + ", it appears to be empty"); return; } sourceHtml = sourceHtml.replace(blockLine, replacement); } catch(e){ console.log("ERROR while creating new reference: "); console.log(e); return; } finally{ // Clean up lockFile.unlockSync('lockfile.lock'); } });
.finally(() => { if ($lockFile != null) { lockfile.unlockSync($lockFile); logger.info('lock released', $buildOpts); } });