From 03f4d418c0fa3f2bcaf8f50103ae275c7990142b Mon Sep 17 00:00:00 2001 From: Karissa McKelvey Date: Fri, 9 Dec 2016 12:27:11 -0800 Subject: [PATCH] attempt to implement temp for clone command. (#19) * attempt to implement temp for clone command. * add --temp doc --- lib/commands/clone.js | 8 ++++++- lib/download.js | 2 ++ package.json | 1 + readme.md | 5 ++++- tests/clone.js | 50 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/lib/commands/clone.js b/lib/commands/clone.js index 94b2a53..f32ab11 100644 --- a/lib/commands/clone.js +++ b/lib/commands/clone.js @@ -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) { diff --git a/lib/download.js b/lib/download.js index 5a4cf4f..9c4e1f0 100644 --- a/lib/download.js +++ b/lib/download.js @@ -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') @@ -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) diff --git a/package.json b/package.json index 8629573..ffcef5b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/readme.md b/readme.md index 4ade84a..5800fd2 100644 --- a/readme.md +++ b/readme.md @@ -24,11 +24,14 @@ Start sharing your Dat Archive over the network. Will import new or updated file ### Downloading ``` -dat-next clone [] +dat-next clone [] [--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=] diff --git a/tests/clone.js b/tests/clone.js index 9c65759..92d7a7e 100644 --- a/tests/clone.js +++ b/tests/clone.js @@ -94,6 +94,56 @@ test('close sharer', function (t) { }) }) +test('clone - with --temp', function (t) { + // cmd: dat clone + 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) })