dat-ecosystem-archive / docs

Documentation resources for dat and the surrounding ecosystem [ DEPRECATED - see https://github.com/hypercore-protocol/new-website/tree/master/guides for similar functionality. More info on active projects and modules at https://dat-ecosystem.org/ ]

Home Page:https://dat-ecosystem-archive.github.io/docs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

datproject.org download demo deletes current working directory.

TimothyStiles opened this issue · comments

commented

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!
screen shot 2018-03-29 at 3 33 01 pm

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

...