aboutsummaryrefslogtreecommitdiff
path: root/bpkg/pkg-unpack.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-05-22 13:26:33 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-05-22 13:26:33 +0200
commit1373e460b426d5adf3a304a60cd8f3634aface45 (patch)
treed11466b3f641510d351a6ce57ec9c131dd9ce47d /bpkg/pkg-unpack.cxx
parent4fd96434dd9afca5f446275fd037e28a09c85edd (diff)
Unify package archive extraction cases to use common implementation
Diffstat (limited to 'bpkg/pkg-unpack.cxx')
-rw-r--r--bpkg/pkg-unpack.cxx98
1 files changed, 5 insertions, 93 deletions
diff --git a/bpkg/pkg-unpack.cxx b/bpkg/pkg-unpack.cxx
index 483a252..f289c2f 100644
--- a/bpkg/pkg-unpack.cxx
+++ b/bpkg/pkg-unpack.cxx
@@ -12,6 +12,7 @@
#include <libbpkg/manifest.hxx>
+#include <bpkg/archive.hxx>
#include <bpkg/package.hxx>
#include <bpkg/package-odb.hxx>
#include <bpkg/database.hxx>
@@ -322,108 +323,19 @@ namespace bpkg
//
arm = auto_rmdir (d);
- cstrings args;
-
- // See if we need to decompress.
- //
- {
- string e (a.extension ());
-
- if (e == "gz") args.push_back ("gzip");
- else if (e == "bzip2") args.push_back ("bzip2");
- else if (e == "xz") args.push_back ("xz");
- else if (e != "tar")
- fail << "unknown compression method in package " << a;
- }
-
- size_t i (0); // The tar command line start.
- if (!args.empty ())
- {
- args.push_back ("-dc");
- args.push_back (a.string ().c_str ());
- args.push_back (nullptr);
- i = args.size ();
- }
-
- args.push_back (co.tar ().string ().c_str ());
-
- // Add extra options.
- //
- for (const string& o: co.tar_option ())
- args.push_back (o.c_str ());
-
- // -C/--directory -- change to directory.
- //
- args.push_back ("-C");
-
-#ifndef _WIN32
- args.push_back (c.string ().c_str ());
-#else
- // Note that tar misinterprets -C option's absolute paths on Windows,
- // unless only forward slashes are used as directory separators:
- //
- // tar -C c:\a\cfg --force-local -xf c:\a\cfg\libbutl-0.7.0.tar.gz
- // tar: c\:\a\\cfg: Cannot open: No such file or directory
- // tar: Error is not recoverable: exiting now
- //
- string cwd (c.string ());
- replace (cwd.begin (), cwd.end (), '\\', '/');
-
- args.push_back (cwd.c_str ());
-
- // An archive name that has a colon in it specifies a file or device on a
- // remote machine. That makes it impossible to use absolute Windows paths
- // unless we add the --force-local option. Note that BSD tar doesn't
- // support this option.
- //
- args.push_back ("--force-local");
-#endif
-
- args.push_back ("-xf");
- args.push_back (i == 0 ? a.string ().c_str () : "-");
- args.push_back (nullptr);
- args.push_back (nullptr); // Pipe end.
-
- size_t what;
try
{
- process_path dpp;
- process_path tpp;
-
- process dpr;
- process tpr;
-
- if (i != 0)
- dpp = process::path_search (args[what = 0]);
-
- tpp = process::path_search (args[what = i]);
-
- if (verb >= 2)
- print_process (args);
-
- if (i != 0)
- {
- dpr = process (dpp, &args[what = 0], 0, -1);
- tpr = process (tpp, &args[what = i], dpr);
- }
- else
- tpr = process (tpp, &args[what = 0]);
+ pair<process, process> pr (start_extract (co, a, c));
// While it is reasonable to assuming the child process issued
// diagnostics, tar, specifically, doesn't mention the archive name.
//
- if (!(what = i, tpr.wait ()) ||
- !(what = 0, dpr.wait ()))
- fail << "unable to extract package archive " << a;
+ if (!pr.second.wait () || !pr.first.wait ())
+ fail << "unable to extract " << a << " to " << c;
}
catch (const process_error& e)
{
- error << "unable to execute " << args[what] << ": " << e;
-
- if (e.child)
- exit (1);
-
- throw failed ();
+ fail << "unable to extract " << a << " to " << c << ": " << e;
}
mc = sha256 (co, d / manifest_file);