Skip to content

Commit 5ec1a53

Browse files
committed
hack/test-port-forwarding.pl: use platform-independent path on hostSocket
Signed-off-by: Norio Nomura <[email protected]>
1 parent dab62e5 commit 5ec1a53

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

hack/test-port-forwarding.pl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use warnings;
1717

1818
use Config qw(%Config);
19+
use File::Spec::Functions qw(catfile);
1920
use IO::Handle qw();
2021
use Socket qw(inet_ntoa);
2122
use Sys::Hostname qw(hostname);
@@ -35,6 +36,10 @@
3536

3637
my $instDir = qx(limactl list "$instance" --yq .dir);
3738
chomp $instDir;
39+
# platform independent way to add trailing path separator
40+
my $sockDir = catfile($instDir, "sock", "");
41+
# catfile convert '\' to '/' on Windows, but we want to keep it as '\' since golang on Windows prefers '\'
42+
$sockDir =~ s/\//\\/g if $Config{osname} eq "msys";
3843

3944
# If $instance is a filename, add our portForwards to it to enable testing
4045
if (-f $instance) {
@@ -97,10 +102,10 @@
97102
s/sshLocalPort/$sshLocalPort/g;
98103
s/ipv4/$ipv4/g;
99104
s/ipv6/$ipv6/g;
100-
s/instDir/$instDir/g;
105+
s/sockDir\//$sockDir/g;
101106
# forward: 127.0.0.1 899 → 127.0.0.1 799
102107
# ignore: 127.0.0.2 8888
103-
/^(forward|ignore):\s+([0-9.:]+)\s+(\d+)(?:\s+→)?(?:\s+(?:([0-9.:]+)(?:\s+(\d+))|(\/\S+))?)?/;
108+
/^(forward|ignore):\s+([0-9.:]+)\s+(\d+)(?:\s+→)?(?:\s+(?:([0-9.:]+)(?:\s+(\d+))|(\S+))?)?/;
104109
die "Cannot parse test '$_'" unless $1;
105110
my %test; @test{qw(mode guest_ip guest_port host_ip host_port host_socket)} = ($1, $2, $3, $4, $5, $6);
106111

@@ -350,6 +355,6 @@ sub JoinHostPort {
350355
hostIP: 0.0.0.0
351356
352357
- guestPort: 5000
353-
hostSocket: "{{.Dir}}/sock/port5000.sock"
358+
hostSocket: port5000.sock
354359
355-
# forward: 127.0.0.1 5000 → instDir/sock/port5000.sock
360+
# forward: 127.0.0.1 5000 → sockDir/port5000.sock

0 commit comments

Comments
 (0)