2024-08-19 03:21:46 +02:00
|
|
|
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 =
|
2024-08-23 15:08:14 +02:00
|
|
|
let archive = fmt"{repo.path}::{nc.args.archive}"
|
|
|
|
var further_args = nc.args.further_args
|
2024-08-19 03:21:46 +02:00
|
|
|
if nc.args.extract_destination != "":
|
|
|
|
discard existsOrCreateDir(nc.args.extract_destination)
|
|
|
|
setCurrentDir(nc.args.extract_destination)
|
|
|
|
let dir = getCurrentDir()
|
|
|
|
if dir.isEmpty():
|
|
|
|
echo "Restoring..."
|
2024-08-23 13:04:27 +02:00
|
|
|
let ok = run genCommand(cmd = "extract", repo = archive, further_args = further_args)
|
2024-08-19 03:21:46 +02:00
|
|
|
return ok
|
|
|
|
else:
|
2024-08-23 13:31:43 +02:00
|
|
|
echo "Not restoring to non-empty destination\r\nPlease use the --destination flag or cd to an empty directory."
|