aboutsummaryrefslogtreecommitdiff
path: root/bpkg/pkg-unpack.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-01-25 00:25:18 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-02-12 17:33:31 +0300
commitcd4243d92ead437e3d10f1182edffedb0949e13e (patch)
treeb555245dfea7b2cbd12b9ead07620297a91fbbb3 /bpkg/pkg-unpack.cxx
parent6e47a92c73ea590896c1f90d13afafff000c1abc (diff)
Add workaround for tar misinterpreting -C option path on Windows
Diffstat (limited to 'bpkg/pkg-unpack.cxx')
-rw-r--r--bpkg/pkg-unpack.cxx19
1 files changed, 18 insertions, 1 deletions
diff --git a/bpkg/pkg-unpack.cxx b/bpkg/pkg-unpack.cxx
index c066f6f..7afb62c 100644
--- a/bpkg/pkg-unpack.cxx
+++ b/bpkg/pkg-unpack.cxx
@@ -4,6 +4,10 @@
#include <bpkg/pkg-unpack.hxx>
+#ifdef _WIN32
+# include <algorithm> // replace()
+#endif
+
#include <libbutl/process.mxx>
#include <libbpkg/manifest.hxx>
@@ -196,14 +200,27 @@ namespace bpkg
// -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.
//
-#ifdef _WIN32
args.push_back ("--force-local");
#endif