From e0b595a62a9fcb0985676d2a0239b91f0855800f Mon Sep 17 00:00:00 2001 From: Nick Logan Date: Mon, 28 Feb 2022 19:54:23 -0600 Subject: [PATCH] Workaround gnu tar remote file feature GNU tar will try to download remote files if they contain a colon. This works around that issue by prefixing the already-relative paths with './' as needed, as this causes the path to not be parsed as a remote file uri. --- lib/Zef/Service/Shell/tar.rakumod | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Zef/Service/Shell/tar.rakumod b/lib/Zef/Service/Shell/tar.rakumod index ba87a8c7..831bc948 100644 --- a/lib/Zef/Service/Shell/tar.rakumod +++ b/lib/Zef/Service/Shell/tar.rakumod @@ -121,7 +121,7 @@ class Zef::Service::Shell::tar does Extractor { react { my $cwd := $archive-file.parent; my $ENV := %*ENV; - my $proc = Zef::zrun-async('tar', '-zxvf', $archive-file.basename, '-C', $extract-to.relative($cwd)); + my $proc = Zef::zrun-async('tar', '-zxvf', self!cli-path($archive-file.basename), '-C', $extract-to.relative($cwd)); $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout(:bin) { } whenever $proc.stderr(:bin) { } @@ -141,7 +141,7 @@ class Zef::Service::Shell::tar does Extractor { react { my $cwd := $archive-file.parent; my $ENV := %*ENV; - my $proc = Zef::zrun-async('tar', '-zt', '-f', $archive-file.basename); + my $proc = Zef::zrun-async('tar', '-zt', '-f', self!cli-path($archive-file.basename)); $stdout.emit("Command: {$proc.command}"); whenever $proc.stdout(:bin) { $output.append($_) } whenever $proc.stderr(:bin) { } @@ -151,4 +151,13 @@ class Zef::Service::Shell::tar does Extractor { my @extracted-paths = $output.decode.lines; $passed ?? @extracted-paths.grep(*.defined) !! (); } + + # Workaround for https://github.com/ugexe/zef/issues/444 + # We could alternative use --force-local but that requires figuring out which + # flavor of tar we're using. + # Expects $path to already be a relative path string (not an absolute path) + method !cli-path(Str $path --> Str) { + return $path if <./ ../ .\\ ..\\>.grep({ $path.starts-with($_) }); + return './' ~ $path; + } }