Permalink
Browse files

ctrl+c should immediately exit, and only show dl progress after dl ha…

…s started
  • Loading branch information...
maxogden committed Jan 29, 2016
1 parent 2cff1a3 commit 48259222f92bd65b144306924153a6e63eba184d
Showing with 4 additions and 15 deletions.
  1. +4 −15 cli.js
View
19 cli.js
@@ -101,20 +101,10 @@ function download (loc, db) {
}
function startProgressLogging (stats) {
var swarmInterval = setInterval(function () {
setInterval(function () {
printSwarmStatus(stats)
}, 500)
printSwarmStatus(stats)
// intercept ctrl+c and do graceful exit
process.on('SIGINT', function () {
clearInterval(swarmInterval)
if (!stats.swarm) return process.exit(0)
stats.swarm.close(function (err) {
if (err) throw err
else process.exit(0)
})
})
}
function printScanProgress (stats) {
@@ -132,17 +122,16 @@ function printAddProgress (stats, total) {
function printSwarmStatus (stats) {
var swarm = stats.swarm
if (!swarm || swarm.peerCount === 0 && swarm.downloading) return logger.stdout('Finding data sources...\n')
if (!swarm) return logger.stdout('Finding data sources...\n')
var totalCount = swarm.blocks
var downloadCount
if (stats) downloadCount = stats.files + stats.directories
var downloadCount = stats.files + stats.directories
var activePeers = xtend({}, swarm.activeInboundPeers, swarm.activeOutboundPeers)
var activeCount = Object.keys(activePeers).length
var msg = ''
var count = '0'
if (swarm.peerCount > 0) count = activeCount + '/' + swarm.peerCount
if (swarm.downloading || swarm.downloadComplete) {
if ((swarm.downloading || swarm.downloadComplete) && stats.downloaded > 0) {
msg += 'Downloaded ' + downloadCount + '/' + totalCount + ' files' +
' (' + prettyBytes(stats.downloadRate()) + '/s, ' + prettyBytes(stats.downloaded) + ' total)\n'
}

0 comments on commit 4825922

Please sign in to comment.