datproject.org download demo deletes current working directory.
TimothyStiles opened this issue · comments
Hey folks,
Just ran the code below from dat's documentation and when I ran it it deleted my working directory and the code I was working on. Not sure why yet but I thought I'd share it here before I forget. Any ideas on what happened? I hope it's just my own error and new users aren't accidentally deleting their work!
var ram = require('random-access-memory')
var hyperdrive = require('hyperdrive')
var discovery = require('hyperdiscovery')
var mirror = require('mirror-folder')
var link = process.argv[2] // user inputs the dat link
var key = link.replace('dat://', '') // extract the key
var dir = process.cwd() // download to cwd
var archive = hyperdrive(ram, key)
archive.ready(function () {
discovery(archive)
var progress = mirror({name: '/', fs: archive}, dir, function (err) {
console.log('done downloading!')
})
progress.on('put', function (src) {
console.log(src.name, 'downloaded')
})
})
Oh no! Darn, sorry about that!
Mirror-folder makes the two directories look the same, which means deleting local stuff if it doesn't exist on the archive. No good for this example!
var mkdirp = require('mkdirp')
...
var dir = path.join(process.cwd(), 'download') // CHANGE DOWNLOAD DIR
mkdirp.sync(dir) // make dir
...
Thanks for opening this!