From: jingui.ren Date: Fri, 23 Mar 2018 01:57:13 +0000 (+0800) Subject: Fix bugs when linux usernames including backslash X-Git-Tag: submit/devel/20190730.074511~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d14658c0057aca2a613bb00e205aa2ba71802ecb;p=tools%2Fdepanneur.git Fix bugs when linux usernames including backslash Change-Id: I65baa482dd5f4048b340ecbbcb8780f1fd68ffa3 Signed-off-by: jingui.ren --- diff --git a/depanneur b/depanneur index 0644956..d7a0204 100755 --- a/depanneur +++ b/depanneur @@ -188,7 +188,6 @@ my $disable_debuginfo = 0;#disable debuginfo when using build cmd my $depends = 0; #depends subcommand to put reverse dependency my $reverse_off = 0; #disable reverse dependency my $reverse_on = 1; #enable reverse dependency - GetOptions ( "repository=s" => \@repos, "arch=s" => \$arch, @@ -541,7 +540,7 @@ if ( $exclude_from_file ne "" && -e $exclude_from_file ) { } -mkdir_p($order_dir); +mkdir_p("$order_dir"); mkdir_p($success_logs_path); mkdir_p($fail_logs_path); mkdir_p($cache_path); @@ -641,7 +640,7 @@ sub fill_packs_from_git { if ($includeall == 0 || $spec_commit ne "") { my (undef, $tmp_file) = tempfile(OPEN => 0); my $__commit = $spec_commit eq "" ? $commit : $spec_commit; - if (my_system("cd $base; git show $__commit:$l_packaging_dir >$tmp_file 2>/dev/null") == 0) { + if (my_system("cd '$base'; git show $__commit:'$l_packaging_dir' >'$tmp_file' 2>/dev/null") == 0) { open my $file, '<', $tmp_file or die $!; # the content like: # tree $__commit:$packaging_dir @@ -671,7 +670,7 @@ sub fill_packs_from_git { } else { #packaging_dir is a symbol link my (undef, $tmp_symlink_file) = tempfile(OPEN => 0); # git show the real packaging dir - if (my_system("cd $base; git show $__commit:$first_line >$tmp_symlink_file 2>/dev/null") == 0) { + if (my_system("cd '$base'; git show $__commit:'$first_line' >'$tmp_symlink_file' 2>/dev/null") == 0) { open my $symlink_file, '<', $tmp_symlink_file or die $!; my $specs; while (<$symlink_file>) { @@ -723,8 +722,8 @@ sub gbs_export { push @args, "gbs"; push @args, "--debug" if ($debug); push @args, "export"; - push @args, "$base"; - push @args, "-o $out_dir"; + push @args, "'$base'"; + push @args, "-o '$out_dir'"; push @args, "--outdir-directly"; push @args, "--spec $spec"; if ($includeall == 1) { @@ -802,13 +801,13 @@ sub write_cache { } my $src_rpm = "$srpm_repo_path/$cache_key.src.rpm"; - if (-f $src_rpm) { + if (-f "$src_rpm") { # Remove old source rpm packages to build again, or depanneur # will skip packages with src.rpm exists - my_system("rm -f $src_rpm"); + my_system("rm -f '$src_rpm'"); } - open(my $rev1, "+>", $cache_fname) || + open(my $rev1, "+>", "$cache_fname") || die "write reversion cache($cache_fname) failed: $!"; print $rev1 $cache_val . "\n"; close($rev1); @@ -832,7 +831,7 @@ sub query_git_commit_rev { my ($base, $commit_id) = @_; # pipe to read - open(my $git, '-|', "git --git-dir $base/.git rev-parse $commit_id") || + open(my $git, '-|', "git --git-dir '$base'/.git rev-parse $commit_id") || die "query git commit reversion($commit_id) failed: $!"; my $rev = readline($git); close($git); @@ -867,7 +866,7 @@ sub prepare_git { # \Q and \E to keep the raw string not be escaped $spec =~ s!\Q$base/\E!!; $without_base = $spec; - if (my_system("cd $base; git show $spec_commit:$without_base >$tmp_spec 2>/dev/null") != 0) { + if (my_system("cd '$base'; git show $spec_commit:$without_base >'$tmp_spec' 2>/dev/null") != 0) { warning("failed to checkout spec file from commit: $spec_commit:$without_base"); return; } @@ -908,8 +907,8 @@ sub prepare_git { my $exported_key = basename($source_cache{"$base:$current_rev"}); # if one package have multiple spec files # No need to export, just copy one - my_system("cp -r $pkg_path/$exported_key $pkg_path/$cache_key"); - my_system("cp -f $pkg_path/cache/$exported_key $pkg_path/cache/$cache_key"); + my_system("cp -r '$pkg_path'/'$exported_key' '$pkg_path'/'$cache_key'"); + my_system("cp -f '$pkg_path'/cache/'$exported_key' '$pkg_path'/cache/'$cache_key'"); } else { # if it's failed to write cache @@ -1038,7 +1037,7 @@ sub refresh_repo { my %packs_arch; my %packs_done; - open(my $fh, '<', $rpmdeps) || die("$rpmdeps: $!\n"); + open(my $fh, '<', "$rpmdeps") || die("$rpmdeps: $!\n"); # WARNING: the following code assumes that the 'I' tag comes last # .repo.cache like: # F:acl.i586-1373460453/1373460459/0: http://.../packages/i586/acl-2.2.49-2.1.i586.rpm @@ -1262,14 +1261,14 @@ sub createrepo my $extra_opts = "--changelog-limit=0 -q"; if ($skip_srcrpm == 0){ - my_system("touch $srpm_repo_path"); + my_system("touch '$srpm_repo_path'"); } - my_system("touch $rpm_repo_path"); + my_system("touch '$rpm_repo_path'"); # if local repo has been created, run createrepo with --update $extra_opts = $extra_opts . " --update " if ( -e "$localrepo/$dist/$arch/repodata" ); $extra_opts = $extra_opts . " --groupfile=$groupfile " if ( -e "$groupfile"); - my_system ("createrepo $extra_opts $localrepo/$dist/$arch > /dev/null 2>&1 ") == 0 or die "createrepo failed: $?\n"; + my_system ("createrepo $extra_opts '$localrepo/$dist/$arch' > /dev/null 2>&1 ") == 0 or die "createrepo failed: $?\n"; } @@ -1737,7 +1736,7 @@ sub get_source_base_name { #--------------------------------------------------------------------- sub worker_thread { my ($name, $thread, $index) = @_; - + debug("call build process:"); my $status; eval { # call build process @@ -1781,14 +1780,14 @@ sub worker_thread { #--------------------------------------------------------------------- sub safe_umount { my ($device) = @_; - return if (my_system("sudo /bin/umount -l $device") == 0); + return if (my_system("sudo /bin/umount -l '$device'") == 0); warning("!!!! umount device $device failed. It may cause files lost in ". "some cases. Please stop the process which is using this device and ". "press any key to umount again !!!!"); <>; - if (my_system("sudo /bin/umount -l -f $device") != 0) { + if (my_system("sudo /bin/umount -l -f '$device'") != 0) { warning("!!!! IMPORTANT: umount failed again, please backup your ". "source code and try to umount manually !!!!"); } @@ -1841,7 +1840,7 @@ sub update_repo_with_rpms { my $na = "$name$arch"; if (exists $ref_hash->{$na}) { foreach (@{$ref_hash->{$na}}) { - my_system("rm -rf $_"); + my_system("rm -rf '$_'"); } } $ref_hash->{$na} = [$pkg]; @@ -1895,7 +1894,7 @@ sub build_package { } else { warning("depanneur only support linux platform"); } - my $target_arch=`$build_dir/queryconfig target --dist $dist --configdir $dist_configs --archpath $arch`; + my $target_arch=`$build_dir/queryconfig target --dist '$dist' --configdir '$dist_configs' --archpath '$arch'`; chomp $target_arch; if ($target_arch eq "") { push @args, "--target $arch"; @@ -1906,12 +1905,12 @@ sub build_package { push @args, "--no-init" if ($noinit == 1); push @args, "--keep-packs" if ($keep_packs == 1); push @args, "--use-higher-deps" if ($use_higher_deps == 1); - push @args, "--cachedir $cache_dir"; - push @args, "--dist $dist_configs/$dist.conf"; - push @args, "--arch $archpath"; - push @args, "$srpm_filename"; + push @args, "--cachedir '$cache_dir'"; + push @args, "--dist '$dist_configs'/$dist.conf"; + push @args, "--arch '$archpath'"; + push @args, "'$srpm_filename'"; push @args, "--ccache" if ($ccache); - push @args, "--icecream $icecream" if ($icecream); + push @args, "--icecream '$icecream'" if ($icecream); push @args, "--baselibs" if ($create_baselibs); if (! $extra_packs eq "") { my $packs = join(' ', split(',', $extra_packs)); @@ -1923,7 +1922,7 @@ sub build_package { info("*** [$index/$count] building $name-$version-$release $arch $dist (worker: $thread) ***"); if ( -d "$rpm_repo_path" ) { - push @args, "--repository $rpm_repo_path"; + push @args, "--repository '$rpm_repo_path'"; } foreach my $r (@package_repos) { push @args, "--repository $r"; @@ -1969,11 +1968,11 @@ sub build_package { } push @args, "--debug" if ($disable_debuginfo != 1); - push @args, "--root $scratch"; - if ($noinit == 1 && -e "$scratch/not-ready") { + push @args, "--root '$scratch'"; + if ($noinit == 1 && -e "'$scratch'/not-ready") { error("build root is not ready , --noinit is not allowed"); } - push @args, "--clean" if (-e "$scratch/not-ready"); + push @args, "--clean" if (-e "'$scratch'/not-ready"); push @args, $redirect; for my $define (@defines) { push @args, "--define '$define'"; @@ -2011,7 +2010,7 @@ sub build_package { push @args, "--define '%reconfigure echo'"; push @args, "--define '%autogen echo'"; } - push @args, "--root $scratch"; + push @args, "--root '$scratch'"; push @args, "--no-topdir-cleanup"; push @args, "--no-init"; @args = grep { $_ ne "--clean"} @args; @@ -2019,25 +2018,25 @@ sub build_package { my $project_base_path = $to_build{$name}->{project_base_path}; if (! -e "$builddir") { - my_system("sudo /bin/mkdir -p $builddir"); + my_system("sudo /bin/mkdir -p '$builddir'"); } - my $mount = "sudo /bin/mount -o bind $project_base_path $builddir"; + my $mount = "sudo /bin/mount -o bind '$project_base_path' '$builddir'"; my_system($mount); my $tmp_dir = abs_path(tempdir(CLEANUP=>1)); - my_system("tar -zcf $source_tar $tmp_dir") if ($source_tar ne ""); + my_system("tar -zcf '$source_tar' '$tmp_dir'") if ("$source_tar" ne ""); } if ($not_ex) { if ( -d "$builddir") { - my_system("rm -rf $builddir"); + my_system("rm -rf '$builddir'"); } my $otherdir = "$scratch/home/abuild/rpmbuild/OTHER/"; if ( ! -d "$otherdir") { - my_system("sudo /bin/mkdir -p $otherdir"); + my_system("sudo /bin/mkdir -p '$otherdir'"); } my $project_base_path = $to_build{$name}->{project_base_path}; - my_system("sudo /bin/mkdir -p $builddir"); - my $mount = "sudo /bin/mount -o bind $project_base_path $builddir"; + my_system("sudo /bin/mkdir -p '$builddir'"); + my $mount = "sudo /bin/mount -o bind '$project_base_path' '$builddir'"; my_system($mount); my $packaing_files = dirname($to_build{$name}->{filename}); my_system("cp -a $packaing_files/* $project_base_path/"); @@ -2050,21 +2049,21 @@ sub build_package { } $cmd = join(" ", @args); - debug($cmd); + #debug($cmd); my $ret = my_system ($cmd); if ($incremental == 1) { #FIXME: more safe way needed to remove this fake source tar - my_system("rm -f $source_tar") if ($source_tar ne ""); + my_system("rm -f '$source_tar'") if ($source_tar ne ""); safe_umount($builddir) if ($incremental == 1); } if ($not_ex) { - my_system("rm -f $source_tar") if ($source_tar ne ""); + my_system("rm -f '$source_tar'") if ($source_tar ne ""); safe_umount($builddir) } # Save build config to build root for --noinit use - my_system("sudo /bin/cp $dist_configs/$dist.conf $scratch/$dist.conf") if ($noinit == 0); + my_system("sudo /bin/cp '$dist_configs/$dist.conf' '$scratch'/$dist.conf") if ($noinit == 0); if ($ret == 0) { # Set the real path of RPMS and SRPMS @@ -2075,17 +2074,17 @@ sub build_package { $rpmdirpath = "/.build.packages/RPMS"; $srcrpmdirpath = "/.build.packages/SRPMS"; } else { - $rpmdirpath = `sudo chroot $scratch su -c "rpm --eval %{_rpmdir} 2>/dev/null" - abuild`; - $srcrpmdirpath = `sudo chroot $scratch su -c "rpm --eval %{_srcrpmdir} 2>/dev/null" - abuild`; + $rpmdirpath = `sudo chroot '$scratch' su -c "rpm --eval %{_rpmdir} 2>/dev/null" - abuild`; + $srcrpmdirpath = `sudo chroot '$scratch' su -c "rpm --eval %{_srcrpmdir} 2>/dev/null" - abuild`; } chomp($rpmdirpath); chomp($srcrpmdirpath); mkdir_p "$success_logs_path/$name-$version-$release"; if (-e "$logpath") { - my_system ("sudo /bin/mv $logpath $success_logs_path/$name-$version-$release/log.txt"); + my_system ("sudo /bin/mv '$logpath' '$success_logs_path'/$name-$version-$release/log.txt"); if ($vmtype eq "kvm") { my $dir_logpath = dirname($logpath); - my_system ("/bin/rm -rf $dir_logpath"); + my_system ("/bin/rm -rf '$dir_logpath'"); } $succeeded{"$name"} = "$success_logs_path/$name-$version-$release/log.txt"; } @@ -2093,30 +2092,35 @@ sub build_package { { # Update global local repo, so lock it lock($DETACHING); - if (my @srpms = bsd_glob "$scratch/$srcrpmdirpath/*.rpm") { +# if (my @srpms = bsd_glob "$scratch/$srcrpmdirpath/*.rpm") { + if (my @srpms = (`find "$scratch/$srcrpmdirpath" -type f -name "*.rpm" 2>/dev/null`)) { #remove old srpms in local repo #copy the new ones to local repo update_repo_with_rpms(\%srpmpaths, @srpms); if ($skip_srcrpm == 0){ foreach (@srpms) { - my_system ("sudo ln $_ $srpm_repo_path"); + $_ =~ s/\n//; + my_system ("sudo ln '$_' '$srpm_repo_path'"); } } } elsif ($skip_srcrpm == 1){ - my_system("/bin/rm -rf $srpm_repo_path/*.rpm"); + my_system("/bin/rm -rf '$srpm_repo_path'/*.rpm"); } - if (my @rpms = bsd_glob "$scratch/$rpmdirpath/*/*.rpm") { +# if (my @rpms = bsd_glob "$scratch/$rpmdirpath/*/*.rpm") { + if (my @rpms = (`find "$scratch/$rpmdirpath" -type f -name "*.rpm" 2>/dev/null`)) { + #remove old rpms in local repo #remove old rpms in local repo #copy the new ones to local repo update_repo_with_rpms (\%rpmpaths, @rpms); foreach (@rpms) { - my_system ("sudo ln $_ $rpm_repo_path"); + $_ =~ s/\n//; + my_system ("sudo ln '$_' '$rpm_repo_path'"); } } - my_system("$build_dir/createdirdeps $rpm_repo_path > $order_dir/.repo.cache.local "); - my_system("echo D: >> $order_dir/.repo.cache.local"); - my_system("cat $order_dir/.repo.cache.local $order_dir/.repo.cache.remote >$order_dir/.repo.cache"); + my_system("'$build_dir'/createdirdeps '$rpm_repo_path' > '$order_dir'/.repo.cache.local "); + my_system("echo D: >> '$order_dir'/.repo.cache.local"); + my_system("cat '$order_dir'/.repo.cache.local '$order_dir'/.repo.cache.remote >'$order_dir'/.repo.cache"); } info("finished building $name"); $packages_built = 1; @@ -2125,10 +2129,10 @@ sub build_package { mkdir_p "$fail_logs_path/$name-$version-$release"; if ( -f "$logpath" ) { # move failed log from build root - my_system ("sudo /bin/mv $logpath $fail_logs_path/$name-$version-$release/log.txt"); + my_system ("sudo /bin/mv '$logpath' '$fail_logs_path'/$name-$version-$release/log.txt"); if ($vmtype eq "kvm") { my $dir_logpath = dirname($logpath); - my_system ("/bin/rm -rf $dir_logpath"); + my_system ("/bin/rm -rf '$dir_logpath'"); } $errors{"$name"} = "$fail_logs_path/$name-$version-$release/log.txt"; warning("build failed, Leaving the logs in $fail_logs_path/$name-$version-$release/log.txt"); @@ -2161,7 +2165,7 @@ sub update_repo my $tmp_dir = abs_path(tempdir(CLEANUP=>1)); if ( @package_group_rpm != 0 and -e $package_group_rpm[0] ) { #unzip package-group binary and find the patterns.xml - my_system("cd $tmp_dir; rpm2cpio $package_group_rpm[0] | cpio -di "); + my_system("cd '$tmp_dir'; rpm2cpio $package_group_rpm[0] | cpio -di "); ( $patternfile ) = glob("$tmp_dir/*/*/*/patterns.xml"); } if ( -e $patternfile ) { @@ -2425,28 +2429,28 @@ sub generate_depends() { info("retrieving repo metadata..."); my $repos_setup = 1; - my_system("> $order_dir/.repo.cache.local"); + my_system("> '$order_dir'/.repo.cache.local"); if (-d "$rpm_repo_path") { - my_system("$build_dir/createdirdeps $rpm_repo_path >> $order_dir/.repo.cache.local"); - my_system("echo D: >> $order_dir/.repo.cache.local"); + my_system("$build_dir/createdirdeps '$rpm_repo_path' >> '$order_dir'/.repo.cache.local"); + my_system("echo D: >> '$order_dir'/.repo.cache.local"); } - my_system("> $order_dir/.repo.cache.remote"); + my_system("> '$order_dir'/.repo.cache.remote"); foreach my $repo (@package_repos) { my $cmd = ""; if ($repo =~ /^\// && ! -e "$repo/repodata/repomd.xml") { - $cmd = "$build_dir/createdirdeps $repo >> $order_dir/.repo.cache.remote "; + $cmd = "$build_dir/createdirdeps '$repo' >> '$order_dir'/.repo.cache.remote "; } else { - $cmd = "$build_dir/createrepomddeps --cachedir=$cache_dir $repo >> $order_dir/.repo.cache.remote "; + $cmd = "$build_dir/createrepomddeps --cachedir='$cache_dir' '$repo' >> '$order_dir'/.repo.cache.remote "; } debug($cmd); if ( my_system($cmd) == 0 ) { - my_system("echo D: >> $order_dir/.repo.cache.remote"); + my_system("echo D: >> '$order_dir'/.repo.cache.remote"); } else { $repos_setup = 0; } } # Merge local repo cache and remote repo cache - my_system("cat $order_dir/.repo.cache.local $order_dir/.repo.cache.remote >$order_dir/.repo.cache"); + my_system("cat '$order_dir'/.repo.cache.local '$order_dir'/.repo.cache.remote >'$order_dir'/.repo.cache"); if ($repos_setup == 0 ) { error("repo cache creation failed..."); @@ -2608,28 +2612,28 @@ if ($clean_repos && -e "$localrepo/$dist/$arch") { info("retrieving repo metadata..."); my $repos_setup = 1; -my_system("> $order_dir/.repo.cache.local"); +my_system("> '$order_dir'/.repo.cache.local"); if (-d "$rpm_repo_path") { - my_system("$build_dir/createdirdeps $rpm_repo_path >> $order_dir/.repo.cache.local"); - my_system("echo D: >> $order_dir/.repo.cache.local"); + my_system("$build_dir/createdirdeps '$rpm_repo_path' >> '$order_dir'/.repo.cache.local"); + my_system("echo D: >> '$order_dir'/.repo.cache.local"); } -my_system("> $order_dir/.repo.cache.remote"); +my_system("> '$order_dir'/.repo.cache.remote"); foreach my $repo (@package_repos) { my $cmd = ""; if ($repo =~ /^\// && ! -e "$repo/repodata/repomd.xml") { - $cmd = "$build_dir/createdirdeps $repo >> $order_dir/.repo.cache.remote "; + $cmd = "$build_dir/createdirdeps '$repo' >> '$order_dir'/.repo.cache.remote "; } else { - $cmd = "$build_dir/createrepomddeps --cachedir=$cache_dir $repo >> $order_dir/.repo.cache.remote "; + $cmd = "$build_dir/createrepomddeps --cachedir='$cache_dir' '$repo' >> '$order_dir'/.repo.cache.remote "; } debug($cmd); if ( my_system($cmd) == 0 ) { - my_system("echo D: >> $order_dir/.repo.cache.remote"); + my_system("echo D: >> '$order_dir'/.repo.cache.remote"); } else { $repos_setup = 0; } } # Merge local repo cache and remote repo cache -my_system("cat $order_dir/.repo.cache.local $order_dir/.repo.cache.remote >$order_dir/.repo.cache"); +my_system("cat '$order_dir'/.repo.cache.local '$order_dir'/.repo.cache.remote >'$order_dir'/.repo.cache"); if ($repos_setup == 0 ) { error("repo cache creation failed..."); @@ -2739,7 +2743,9 @@ for(my $i = 0; $i < $MAX_THREADS; $i++) { } # scan local repo -for my $pkg (bsd_glob "$rpm_repo_path/*.rpm") { +#for my $pkg (bsd_glob "$rpm_repo_path/*.rpm") { +for my $pkg (`find "$rpm_repo_path" -type f -name "*.rpm" 2>/dev/null`) { + $pkg =~ s/\n//; my ($name, $version, $release, $arch) = get_pkg_info $pkg; next if $name eq ''; my $na = "$name$arch"; @@ -2749,7 +2755,9 @@ for my $pkg (bsd_glob "$rpm_repo_path/*.rpm") { $rpmpaths{$na} = [$pkg]; } } -for my $pkg (bsd_glob "$srpm_repo_path/*.rpm") { +#for my $pkg (bsd_glob "$srpm_repo_path/*.rpm") { +for my $pkg (`find "$srpm_repo_path" -type f -name "*.rpm" 2>/dev/null`) { + $pkg =~ s/\n//; my ($name, $version, $release, $arch) = get_pkg_info $pkg; next if $name eq ''; my $na = "$name$arch"; @@ -2790,7 +2798,6 @@ if ($debug) { print "\n"; } } - # Main process loop # Every loop, first update package information # include dependencies if there is new package @@ -2808,7 +2815,7 @@ while (! $TERM) { if ($dirty) { # there is any package has been built refresh_repo(); - update_expansion_errors(); + update_expansion_errors(); #update_pkgdeps(); #update_pkgddeps(); #if (check_circle() == 1) { @@ -2818,7 +2825,6 @@ while (! $TERM) { $dirty = 0; } - foreach my $name (@build_order) { # skip the followint packages: # - packages already done (in @done list) @@ -2852,7 +2858,6 @@ while (! $TERM) { push(@order_clean, $name); } } - #remove unuseful package name from build_order foreach my $u_name (@order_clean) { @build_order = grep { $_ ne $u_name} @build_order; @@ -2934,7 +2939,6 @@ while (! $TERM) { while ((threads->list() > 0)) { sleep(1); } - update_repo(); build_report();