package Iurt::File; use base qw(Exporter); use File::Copy 'move'; use File::Path 'make_path'; use Iurt::Util qw(plog); use strict; our @EXPORT = qw( check_upload_tree cleanup_failed_build ); sub check_upload_tree { my ($todo, $func, $o_post) = @_; # Squash double slashes for cosmetics $todo =~ s!/+!/!g; opendir(my $dir, $todo); plog('INFO', "check dir: $todo"); foreach my $f (readdir $dir) { $f =~ /^\.{1,2}$/ and next; if (-d "$todo/$f") { plog('DEBUG', "checking target $todo/$f"); opendir my $target_dir, "$todo/$f"; foreach my $m (readdir $target_dir) { $m =~ /^\.{1,2}$/ and next; if (-d "$todo/$f/$m") { plog('DEBUG', "checking media $todo/$f/$m"); opendir my $media_dir, "$todo/$f/$m"; foreach my $s (readdir $media_dir) { $s =~ /^\.{1,2}$/ and next; if (-d "$todo/$f/$m/$s") { if ($func) { opendir my $submedia_dir, "$todo/$f/$m/$s"; foreach my $r (readdir $submedia_dir) { $r =~ /^\.{1,2}$/ and next; $func->($todo, $f, $m, $s, $r); } } # cleaning if ($o_post) { opendir my $submedia_dir, "$todo/$f/$m/$s"; foreach my $r (readdir $submedia_dir) { $r =~ /^\.{1,2}$/ and next; $o_post->($todo, $f, $m, $s, $r); } } } else { # may need to check also here for old target } } } } } } } sub cleanup_failed_build { my ($todo_dir, $done_dir, $fail_dir, $prefix, $ent) = @_; foreach my $rpm (@{$ent->{rpms}}) { my $file = "$done_dir/${prefix}_$rpm"; plog('DEBUG', "moving built rpm $file to $fail_dir/"); move($file, "$fail_dir/${prefix}_$rpm"); } delete $ent->{rpms}; foreach my $srpm (@{$ent->{srpms}}) { my $file = "$todo_dir/${prefix}_$srpm"; plog('DEBUG', "moving $file to $fail_dir/"); move($file, "$fail_dir/${prefix}_$srpm"); # If one arch has been generated, we also have a src.rpm in done $file = "$done_dir/${prefix}_$srpm"; if (-f $file) { plog('DEBUG', "deleting $file"); unlink $file; } } if (-d "$done_dir/$prefix") { make_path("$fail_dir/$prefix"); foreach my $file (glob "$done_dir/$prefix/*") { plog('DEBUG', "moving $file to $fail_dir/$prefix/"); move($file, "$fail_dir/$prefix/"); } } }