From cd4243d92ead437e3d10f1182edffedb0949e13e Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 25 Jan 2018 00:25:18 +0300 Subject: Add workaround for tar misinterpreting -C option path on Windows --- bpkg/pkg-unpack.cxx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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 +#ifdef _WIN32 +# include // replace() +#endif + #include #include @@ -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 -- cgit v1.1