From cfa040c8708a5672cae8202207544f2b9e5aa099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lesimple?= Date: Fri, 5 Jun 2026 12:28:45 +0000 Subject: [PATCH] fix: build_ttyrec_cmdline_part1of2: don't mkdir when mocking --- lib/perl/OVH/Bastion.pm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/perl/OVH/Bastion.pm b/lib/perl/OVH/Bastion.pm index 20a4987..135ef32 100644 --- a/lib/perl/OVH/Bastion.pm +++ b/lib/perl/OVH/Bastion.pm @@ -1280,16 +1280,19 @@ sub build_ttyrec_cmdline_part1of2 { return R('ERR_SECURITY_VIOLATION', msg => "Refusing to use unsafe ttyrec path '$pathFormat'"); } - # split into directory + filename, and create the directory tree (best-effort, default perms) + # split into directory + filename, and create the directory tree (best-effort, default perms). + # under mocking (unit tests), skip the actual mkdir so we never touch the real filesystem. my ($saveDir, $ttyrecFilenameFormat) = $pathFormat =~ m{^(.*)/([^/]+)$}; if (!$saveDir || !$ttyrecFilenameFormat) { return R('ERR_INVALID_PARAMETER', msg => "Invalid ttyrec path '$pathFormat'"); } - my $mkpath = ''; - foreach my $component (split m{/}, $saveDir) { - next if !$component; - $mkpath .= "/$component"; - mkdir($mkpath); # ignore errors: parent directories likely already exist + if (!OVH::Bastion::is_mocking()) { + my $mkpath = ''; + foreach my $component (split m{/}, $saveDir) { + next if !$component; + $mkpath .= "/$component"; + mkdir($mkpath); # ignore errors: parent directories likely already exist + } } my $saveFileFormat = "$saveDir/$ttyrecFilenameFormat";