norgbackup/norg/borg/extract.nim

24 lines
816 B
Nim

import ../model/config_type
import execute
import strformat
import os
proc isEmpty(dir: string): bool =
var count = 0
for idx, f in walkDir(dir): return false
#count += 1
return count == 0
proc extractArchive*(nc: NorgConfig, repo: Repository): int =
let archive = fmt"{repo.path}::{nc.args.further_args[0]}"
var further_args = nc.args.further_args[1..^1]
if nc.args.extract_destination != "":
discard existsOrCreateDir(nc.args.extract_destination)
setCurrentDir(nc.args.extract_destination)
let dir = getCurrentDir()
if dir.isEmpty():
echo "Restoring..."
let ok = run genCommand(cmd = "extract", repo = archive, further_args = further_args)
return ok
else:
echo "Not restoring to non-empty destination\r\nPlease use the --destination flag or cd to an empty directory."