mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-30836 MTR Cygwin subshell wrapper fix
See "Path-style conflict" in "MDEV-30836 MTR Cygwin fix" for explanation. To install subshell fix use --cygwin-subshell-fix=do To uninstall use --cygwin-subshell-fix=remove This works only from Cygwin environment. As long as perl on PATH is from Cygwin you are on Cygwin environment. Check it with perl --version This is perl 5, version 36, subversion 1 (v5.36.1) built for x86_64-cygwin-threads-multi
This commit is contained in:
committed by
Daniel Black
parent
0815a3b6b5
commit
4ed583031a
@ -20,6 +20,7 @@ package My::Platform;
|
||||
use strict;
|
||||
use File::Basename;
|
||||
use File::Path;
|
||||
use Carp;
|
||||
|
||||
use base qw(Exporter);
|
||||
our @EXPORT= qw(IS_CYGWIN IS_WINDOWS IS_WIN32PERL IS_AIX
|
||||
@ -219,4 +220,69 @@ sub open_for_append
|
||||
}
|
||||
|
||||
|
||||
sub check_cygwin_subshell
|
||||
{
|
||||
# Only pipe (or sh-expansion) is fed to /bin/sh
|
||||
my $out= `echo %comspec%|cat`;
|
||||
return ($out =~ /\bcmd.exe\b/) ? 0 : 1;
|
||||
}
|
||||
|
||||
sub install_shell_wrapper()
|
||||
{
|
||||
system("rm -f /bin/sh.exe") and die $!;
|
||||
my $wrapper= <<'EOF';
|
||||
#!/bin/bash
|
||||
if [[ -n "$MTR_PERL" && "$1" = "-c" ]]; then
|
||||
shift
|
||||
exec $(cygpath -m "$COMSPEC") /C "$@"
|
||||
fi
|
||||
exec /bin/bash "$@"
|
||||
EOF
|
||||
open(OUT, '>', "/bin/sh") or die "/bin/sh: $!\n";
|
||||
print OUT $wrapper;
|
||||
close(OUT);
|
||||
system("chmod +x /bin/sh") and die $!;
|
||||
print "Cygwin subshell wrapper /bin/sh was installed, please restart MTR!\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
sub uninstall_shell_wrapper()
|
||||
{
|
||||
system("rm -f /bin/sh") and die $!;
|
||||
system("cp /bin/bash.exe /bin/sh.exe") and die $!;
|
||||
}
|
||||
|
||||
sub cygwin_subshell_fix
|
||||
{
|
||||
my ($opt_name, $opt_value)= @_;
|
||||
if ($opt_name ne "cygwin-subshell-fix") {
|
||||
confess "Wrong option name: ${opt_name}";
|
||||
}
|
||||
if ($opt_value eq "do") {
|
||||
if (check_cygwin_subshell()) {
|
||||
install_shell_wrapper();
|
||||
} else {
|
||||
print "Cygwin subshell fix was already installed, skipping...\n";
|
||||
}
|
||||
} elsif ($opt_value eq "remove") {
|
||||
if (check_cygwin_subshell()) {
|
||||
print "Cygwin subshell fix was already uninstalled, skipping...\n";
|
||||
} else {
|
||||
uninstall_shell_wrapper();
|
||||
}
|
||||
} else {
|
||||
die "Wrong --cygwin-subshell-fix value: ${opt_value} (expected do/remove)";
|
||||
}
|
||||
}
|
||||
|
||||
sub options
|
||||
{
|
||||
if (IS_CYGWIN) {
|
||||
return ('cygwin-subshell-fix=s' => \&cygwin_subshell_fix);
|
||||
} else {
|
||||
return ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
Reference in New Issue
Block a user