Skip to content

Commit

Permalink
modify --exit for dat pull command, so that it exits after specified …
Browse files Browse the repository at this point in the history
…number of seconds, when there are no updates to sync. (#1098)
  • Loading branch information
joelwreed authored and joehand committed Apr 17, 2019
1 parent 66179ff commit 77a5b28
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]
*Note: unreleased changes are added here.*
* `dat pull --exit=NN` exits after `NN` number of seconds, when there are no updates to sync.

## 13.9.0 - 2017-10-11

Expand Down
12 changes: 11 additions & 1 deletion src/commands/pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ module.exports = {
'Usage: dat pull'
].join('\n'),
options: [
{
name: 'exit',
boolean: false,
help: 'exit after specified number of seconds (gives the dat network time to find updates). defaults to 12 seconds.'
},

{
name: 'upload',
boolean: true,
Expand Down Expand Up @@ -58,7 +64,11 @@ function pull (opts) {

// Force these options for pull command
opts.createIfMissing = false
opts.exit = true

// If --exit is specified without a number of seconds, default to 12
if (opts.exit === true) {
opts.exit = 12
}

var neat = neatLog(archiveUI, { logspeed: opts.logspeed, quiet: opts.quiet, debug: opts.debug })
neat.use(trackArchive)
Expand Down
11 changes: 9 additions & 2 deletions src/lib/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ function trackDownload (state, bus) {
archive.on('sync', function () {
debug('archive sync', state.stats.get())
state.download.nsync = true
var shouldExit = (state.download.modified && state.opts.exit)
if (shouldExit) return exit()
// if we are supposed to exit, do so if we've pulled changes or have given the network the desired wait time
if (state.opts.exit) {
if (state.download.modified) {
return exit()
} else {
var delayInMilliseconds = 1000 * state.opts.exit
setTimeout(exit, delayInMilliseconds)
}
}
if (state.dat.archive.version === 0) {
// TODO: deal with this.
// Sync sometimes fires early when it should wait for update.
Expand Down
4 changes: 4 additions & 0 deletions src/ui/components/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ function networkUI (state) {
}
}

if (state.opts.exit) {
title = `dat synced, exiting in ${state.opts.exit} seconds.`
}

if (!stats.downloaded || !stats.length) {
return '' // no metadata yet
}
Expand Down

0 comments on commit 77a5b28

Please sign in to comment.