Skip to content

Commit 77a5b28

Browse files
joelreed-oajoehand
authored andcommitted
modify --exit for dat pull command, so that it exits after specified number of seconds, when there are no updates to sync. (#1098)
1 parent 66179ff commit 77a5b28

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](https://semver.org/).
44

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

88
## 13.9.0 - 2017-10-11
99

src/commands/pull.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ module.exports = {
77
'Usage: dat pull'
88
].join('\n'),
99
options: [
10+
{
11+
name: 'exit',
12+
boolean: false,
13+
help: 'exit after specified number of seconds (gives the dat network time to find updates). defaults to 12 seconds.'
14+
},
15+
1016
{
1117
name: 'upload',
1218
boolean: true,
@@ -58,7 +64,11 @@ function pull (opts) {
5864

5965
// Force these options for pull command
6066
opts.createIfMissing = false
61-
opts.exit = true
67+
68+
// If --exit is specified without a number of seconds, default to 12
69+
if (opts.exit === true) {
70+
opts.exit = 12
71+
}
6272

6373
var neat = neatLog(archiveUI, { logspeed: opts.logspeed, quiet: opts.quiet, debug: opts.debug })
6474
neat.use(trackArchive)

src/lib/download.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,15 @@ function trackDownload (state, bus) {
3232
archive.on('sync', function () {
3333
debug('archive sync', state.stats.get())
3434
state.download.nsync = true
35-
var shouldExit = (state.download.modified && state.opts.exit)
36-
if (shouldExit) return exit()
35+
// if we are supposed to exit, do so if we've pulled changes or have given the network the desired wait time
36+
if (state.opts.exit) {
37+
if (state.download.modified) {
38+
return exit()
39+
} else {
40+
var delayInMilliseconds = 1000 * state.opts.exit
41+
setTimeout(exit, delayInMilliseconds)
42+
}
43+
}
3744
if (state.dat.archive.version === 0) {
3845
// TODO: deal with this.
3946
// Sync sometimes fires early when it should wait for update.

src/ui/components/download.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ function networkUI (state) {
2626
}
2727
}
2828

29+
if (state.opts.exit) {
30+
title = `dat synced, exiting in ${state.opts.exit} seconds.`
31+
}
32+
2933
if (!stats.downloaded || !stats.length) {
3034
return '' // no metadata yet
3135
}

0 commit comments

Comments
 (0)