Skip to content

Commit f4b8254

Browse files
committed
Update: using client.drive.import
1 parent f1c7fee commit f4b8254

1 file changed

Lines changed: 7 additions & 20 deletions

File tree

bin/commands/import.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ const fs = require('fs').promises
22
const p = require('path')
33

44
const cliProgress = require('cli-progress')
5-
const mirrorFolder = require('mirror-folder')
65
const { flags } = require('@oclif/command')
76

87
const DaemonCommand = require('../../lib/cli')
9-
const { HyperdriveClient } = require('../..')
108

11-
const IMPORT_KEY_FILE_PATH = '.hyperdrive-import-key'
12-
const EXPORT_KEY_FILE_PATH = '.hyperdrive-export-key'
9+
const {
10+
importKeyFilePath: IMPORT_KEY_FILE_PATH,
11+
exportKeyFilePath: EXPORT_KEY_FILE_PATH
12+
} = require('../../lib/constants')
1313

1414
class ImportCommand extends DaemonCommand {
1515
static usage = 'import [dir] [key]'
@@ -64,16 +64,8 @@ class ImportCommand extends DaemonCommand {
6464
console.log(`Importing ${args.dir} into ${drive.key.toString('hex')} (Ctrl+c to exit)...`)
6565
console.log()
6666

67-
const localMirror = mirrorFolder(args.dir, { fs: drive, name: '/' }, {
68-
watch: true,
69-
dereference: true,
70-
// When going from fs -> drive, it should overwrite.
71-
keepExisting: false,
72-
ignore: (file, stat, cb) => {
73-
if (shouldIgnore(file)) return process.nextTick(cb, null, true)
74-
return process.nextTick(cb, null, false)
75-
}
76-
})
67+
const localMirror = this.client.drive.import(args.dir, drive)
68+
7769
localMirror.on('pending', ({ name }) => {
7870
if (shouldIgnore(name)) return
7971
progress.setTotal(++total)
@@ -116,12 +108,7 @@ class ImportCommand extends DaemonCommand {
116108
return fs.writeFile(keyPath, drive.key)
117109
}
118110

119-
function shouldIgnore (name) {
120-
if (!name) return true
121-
if (name.indexOf(EXPORT_KEY_FILE_PATH) !== -1) return true
122-
else if (name.indexOf(IMPORT_KEY_FILE_PATH) !== -1) return true
123-
return false
124-
}
111+
125112
}
126113
}
127114

0 commit comments

Comments
 (0)