From 09495a118b165d60d17780a8623318c19d6ffae6 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Fri, 14 Jul 2006 02:04:06 +0000 Subject: Bug 344298: importxml.pl performance problem - Patch by Vance Baarda r=ghendricks a=myk --- importxml.pl | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'importxml.pl') diff --git a/importxml.pl b/importxml.pl index 6ed2727ea..dbcc72f1c 100755 --- a/importxml.pl +++ b/importxml.pl @@ -100,11 +100,13 @@ Bugzilla->batch(1); my $debug = 0; my $mail = ''; +my $attach_path = ''; my $help = 0; my $result = GetOptions( "verbose|debug+" => \$debug, "mail|sendmail!" => \$mail, + "attach_path=s" => \$attach_path, "help|?" => \$help ); @@ -365,14 +367,24 @@ sub process_attachment() { $attachment{'isprivate'} = $attach->{'att'}->{'isprivate'} || 0; $attachment{'filename'} = $attach->field('filename') || "file"; # Attachment data is not exported in versions 2.20 and older. - if (defined $attach->first_child('data') - && defined $attach->first_child('data')->{'att'}->{'encoding'} - && $attach->first_child('data')->{'att'}->{'encoding'} =~ /base64/ ) - { - # decode the base64 - my $data = $attach->field('data'); - my $output = decode_base64($data); - $attachment{'data'} = $output; + if (defined $attach->first_child('data') && + defined $attach->first_child('data')->{'att'}->{'encoding'}) { + my $encoding = $attach->first_child('data')->{'att'}->{'encoding'}; + if ($encoding =~ /base64/) { + # decode the base64 + my $data = $attach->field('data'); + my $output = decode_base64($data); + $attachment{'data'} = $output; + } + elsif ($encoding =~ /filename/) { + # read the attachment file + Error("attach_path is required", undef) unless ($attach_path); + my $attach_filename = $attach_path . "/" . $attach->field('data'); + open(ATTACH_FH, $attach_filename) or + Error("cannot open $attach_filename", undef); + $attachment{'data'} = do { local $/; }; + close ATTACH_FH; + } } else { $attachment{'data'} = $attach->field('data'); @@ -1212,6 +1224,8 @@ importxml - Import bugzilla bug data from xml. -v --verbose print error and debug information. Mulltiple -v increases verbosity -m --sendmail send mail to recipients with log of bugs imported + --attach_path The path to the attachment files. + (Required if encoding="filename" is used for attachments.) =head1 OPTIONS -- cgit v1.2.3-24-g4f1b