From 233e9ca92f6dd8dd60970674c7da79cfb72cca16 Mon Sep 17 00:00:00 2001 From: Stephan Barth Date: Thu, 18 Apr 2024 01:29:05 +0200 Subject: [PATCH] chore(gitlab-ci): Add debug print to container sanitation. --- .gitlab-ci/sanitize-docker.pl | 53 +++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci/sanitize-docker.pl b/.gitlab-ci/sanitize-docker.pl index 7ab0194e2..51704aebe 100755 --- a/.gitlab-ci/sanitize-docker.pl +++ b/.gitlab-ci/sanitize-docker.pl @@ -5,17 +5,32 @@ use warnings; use Data::Dumper; +print "Sanitize script for node removal from container.\n"; + +system("pwd"); +{ + my @l = (".",".."); + for(1..8) { + push @l, (("../" x $_)."..") + } + for(@l) { + my $cmd = "ls -ld $_"; + print "running: $cmd\n"; + system $cmd; + } +} + my $tmpdir = "tmp-sanitize"; die "Has already run, abort" if -e $tmpdir; mkdir $tmpdir; -chmod(0755, $tmpdir); +chmodWrap(0755, $tmpdir); chdir($tmpdir); system("ln -s ../uniworx.tar.gz ."); system("tar xzvf uniworx.tar.gz"); -chmod(0755, '.'); # tar can change the rights of '.' if it contains an entry for '.' with other rights +chmodWrap(0755, '.'); # tar can change the rights of '.' if it contains an entry for '.' with other rights my %truerights = (); storeRightsMake7("."); @@ -26,6 +41,25 @@ storeRightsMake7("."); #print "=== Reset rights:\n"; #system("ls -l *"); +sub chmodWrap { + my ($mode, $fn) = @_; + my $tries = 0; + die "file '$fn' does not exist; cannot change its permissions to $mode" unless -e $fn; + RIGHTS: { + chmod($mode, $fn); + my $ismode = (stat($fn))[2]; + my $fm = $ismode % 512; + if($fm != $mode) { + if($tries++ > 20) { + die "Problem with file permissions, abort" + } + warn sprintf "File rights were meant to be set, but were not updated properly for file '%s', is %03o but was set to %03o; try again in 1 second"; + sleep 1; + redo RIGHTS; + } + } +} + # sub storeRightsMake7 { my ($pwd) = @_; @@ -39,7 +73,7 @@ sub storeRightsMake7 { my $fm = $mode % 512; #my $fmo = sprintf("%03o",$fm); $truerights{$fullname} = $fm; - chmod(($fm | 0700), $fullname); + chmodWrap(($fm | 0700), $fullname); storeRightsMake7($fullname) if -d $fullname; } } @@ -55,7 +89,7 @@ sub resetRights { #perl -le 'my $dh = undef;opendir($dh, ".");while(my $fn = readdir($dh)) { my $mode = (stat($fn))[2];my $fm = $mode % 512;my $fmo=sprintf("%03o",$fm);print "$fn -> $fmo" }' my $fullname = "$pwd/$fn"; printf(" set rights of '$fullname' back to %03o\n", $truerights{$fullname}); - chmod($truerights{$fullname}, $fullname); + chmodWrap($truerights{$fullname}, $fullname); resetRights($fullname) if -d $fullname; } } @@ -72,6 +106,12 @@ sub renameWithRights { #my $rights = $truerights{$from}; #delete $truerights{$from}; rename($from, $to) or die "Could not rename '$from' to '$to', because $!"; + my $waittimer = 20; + while(-e $from || not(-e $to) and $waittimer-- > 0) { + sleep 1 + } + die "rename file from '$from' to '$to', but it is still there" if -e $from; + die "rename file from '$from' to '$to', but there is no file under the new name" unless -e $to; #$truerights{$to} = $rights } @@ -176,7 +216,8 @@ sub replaceInFile { } my $wh = undef; open($wh, '>', $filename) or die "Could not write $filename, because: $!"; - print $wh $content + print $wh $content; + close $wh; } my %replacer = ( @@ -214,7 +255,7 @@ cautionWaiter(); resetRights("."); - +system("find"); unlink("uniworx.tar.gz");