show progress for imports and deletions
This commit is contained in:
parent
38eea05789
commit
5e342b6fe5
13 changed files with 343 additions and 115 deletions
|
|
@ -4,6 +4,7 @@ const path = require('path')
|
|||
const fs = require('fs')
|
||||
const { DIRS, readJson, writeJson } = require('./paths')
|
||||
const { rewireSymlinks } = require('./symlinks')
|
||||
const { removeTree, treeSize } = require('./fsutil')
|
||||
const { normalizePathName } = require('./names')
|
||||
|
||||
const REGISTRY = path.join(DIRS.DATA, 'prefixes.json')
|
||||
|
|
@ -71,15 +72,21 @@ function createPrefix(name) {
|
|||
return { ok: true, name: clean }
|
||||
}
|
||||
|
||||
function deletePrefix(name) {
|
||||
// A prefix is a whole windows drive - removal is measured before it starts
|
||||
// (staging) so the UI can show a bar that actually moves while the tree is
|
||||
// walked file by file (removeTree), instead of one blocking rmSync.
|
||||
async function deletePrefix(name, onProgress) {
|
||||
if (String(name).toLowerCase() === MAIN.toLowerCase()) return { ok: false, error: 'isMain' }
|
||||
const defs = listPrefixes()
|
||||
defs.prefixes = defs.prefixes.filter(p => p.name !== name)
|
||||
if (defs.default === name) defs.default = MAIN
|
||||
savePrefixes(defs)
|
||||
try {
|
||||
fs.rmSync(prefixPath(name), { recursive: true, force: true })
|
||||
} catch {}
|
||||
const emit = (phase, detail) => {
|
||||
if (onProgress) onProgress({ phase, label: name, ...detail })
|
||||
}
|
||||
emit('count', { files: 0, bytes: 0 })
|
||||
const total = await treeSize(prefixPath(name))
|
||||
await removeTree(prefixPath(name), p => emit('remove', { files: p.files, bytes: p.bytes, totalFiles: total.files, totalBytes: total.bytes }))
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue