Skip to content

Commit 76cd014

Browse files
committed
Update: using client.drive.import
1 parent be5014b commit 76cd014

1 file changed

Lines changed: 7 additions & 19 deletions

File tree

bin/commands/import.js

Lines changed: 7 additions & 19 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]'
@@ -55,15 +55,8 @@ class ImportCommand extends DaemonCommand {
5555
console.log(`Importing ${args.dir} into ${drive.key.toString('hex')} (Ctrl+c to exit)...`)
5656
console.log()
5757

58-
const localMirror = mirrorFolder(args.dir, { fs: drive, name: '/' }, {
59-
watch: true,
60-
dereference: true,
61-
keepExisting: true,
62-
ignore: (file, stat, cb) => {
63-
if (shouldIgnore(file)) return process.nextTick(cb, null, true)
64-
return process.nextTick(cb, null, false)
65-
}
66-
})
58+
const localMirror = this.client.drive.import(args.dir, drive)
59+
6760
localMirror.on('pending', ({ name }) => {
6861
if (shouldIgnore(name)) return
6962
progress.setTotal(++total)
@@ -106,12 +99,7 @@ class ImportCommand extends DaemonCommand {
10699
return fs.writeFile(keyPath, drive.key)
107100
}
108101

109-
function shouldIgnore (name) {
110-
if (!name) return true
111-
if (name.indexOf(EXPORT_KEY_FILE_PATH) !== -1) return true
112-
else if (name.indexOf(IMPORT_KEY_FILE_PATH) !== -1) return true
113-
return false
114-
}
102+
115103
}
116104
}
117105

0 commit comments

Comments
 (0)