Skip to content

Commit

Permalink
attempt to implement temp for clone command. (#19)
Browse files Browse the repository at this point in the history
* attempt to implement temp for clone command.

* add --temp doc
  • Loading branch information
Karissa authored and joehand committed Dec 9, 2016
1 parent e95825b commit 03f4d41
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/commands/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ var download = require('../download')
module.exports = {
name: 'clone',
command: clone,
options: []
options: [
{
name: 'temp',
boolean: true,
default: false
}
]
}

function clone (opts) {
Expand Down
2 changes: 2 additions & 0 deletions lib/download.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var assert = require('assert')
var logger = require('status-logger')
var prettyBytes = require('pretty-bytes')
var memdb = require('memdb')
var Dat = require('dat-node')
var ui = require('./ui')

Expand Down Expand Up @@ -45,6 +46,7 @@ module.exports = function (type, opts, dat) {
}, opts.logspeed)

// Action starts here
if (opts.temp) opts.db = memdb()
if (!dat) Dat(opts.dir, opts, start)
else start(null, dat)

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dat-doctor": "^1.0.1",
"dat-key-as": "^1.0.0",
"dat-node": "^1.0.0-alpha.2.1.0",
"memdb": "^1.3.1",
"pretty-bytes": "^4.0.2",
"progress-string": "^1.2.1",
"status-logger": "^3.0.0",
Expand Down
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ Start sharing your Dat Archive over the network. Will import new or updated file
### Downloading

```
dat-next clone <dat-link> [<folder>]
dat-next clone <dat-link> [<folder>] [--temp]
```

Clone a remote Dat Archive to a local folder. Will create a folder with the key name is no folder is specified.

##### Options

`--temp`: Creates a temporary database and doesn't save the metadata to disk, only the latest files.

```
dat-next pull [--dir=<folder>]
Expand Down
50 changes: 50 additions & 0 deletions tests/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,56 @@ test('close sharer', function (t) {
})
})

test('clone - with --temp', function (t) {
// cmd: dat clone <link>
help.shareFixtures(function (_, fixturesDat) {
shareDat = fixturesDat
var key = shareDat.key.toString('hex')
var cmd = dat + ' clone ' + key + ' --temp'
var st = spawn(t, cmd, {cwd: baseTestDir})
var datDir = path.join(baseTestDir, key)
st.stdout.match(function (output) {
var downloadFinished = output.indexOf('Download Finished') > -1
if (!downloadFinished) return false

var stats = shareDat.stats.get()
var fileRe = new RegExp(stats.filesTotal + ' files')
var bytesRe = new RegExp(/1\.\d{1,2} kB/)

t.ok(help.matchLink(output), 'prints link')
t.ok(output.indexOf('dat-download-folder/' + key) > -1, 'prints dir')
t.ok(output.match(fileRe), 'total size: files okay')
t.ok(output.match(bytesRe), 'total size: bytes okay')
t.ok(help.isDir(datDir), 'creates download directory')

var fileList = help.fileList(datDir).join(' ')
var hasCsvFile = fileList.indexOf('all_hour.csv') > -1
t.ok(hasCsvFile, 'csv file downloaded')
var hasDatFolder = fileList.indexOf('.dat') > -1
t.ok(!hasDatFolder, '.dat folder not created')
var hasSubDir = fileList.indexOf('folder') > -1
t.ok(hasSubDir, 'folder created')
var hasNestedDir = fileList.indexOf('nested') > -1
t.ok(hasNestedDir, 'nested folder created')
var hasHelloFile = fileList.indexOf('hello.txt') > -1
t.ok(hasHelloFile, 'hello.txt file downloaded')

st.kill()
return true
})
st.succeeds('exits after finishing download')
st.stderr.empty()
st.end()
})
})

test('close sharer', function (t) {
shareDat.close(function () {
rimraf.sync(path.join(shareDat.path, '.dat'))
t.end()
})
})

test.onFinish(function () {
rimraf.sync(baseTestDir)
})

0 comments on commit 03f4d41

Please sign in to comment.