extract.ha 749 B

1234567891011121314151617181920212223242526272829303132
  1. use os;
  2. use fs;
  3. use path;
  4. use memio;
  5. use fmt;
  6. use shlex;
  7. use a;
  8. use a::archives;
  9. fn extract(cfg: *const a::Config, archive_path: const str) void = {
  10. let path = match (os::realpath(archive_path)) {
  11. case let p: str => yield p;
  12. case let e: fs::error =>
  13. a::fatal(cfg, "failed to get realpath from '{}': {}", archive_path, fs::strerror(e));
  14. };
  15. a::create_out_dir(cfg);
  16. match (os::chdir(cfg.out_dir)) {
  17. case let e: fs::error =>
  18. a::fatal(cfg, "failed to change directrory to '{}': {}", cfg.out_dir, fs::strerror(e));
  19. case void => void;
  20. };
  21. if (cfg.dry_run) {
  22. fmt::print("cd ")!;
  23. shlex::quote(os::stdout, cfg.out_dir)!;
  24. fmt::print(" \\\n&& ")!;
  25. };
  26. archives::dryrun_or_exec(cfg.dry_run, CMD, if (cfg.verbose) "vx" else "x", path);
  27. };