summaryrefslogtreecommitdiffstats
path: root/scripts/attachment-data.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/attachment-data.pl')
-rwxr-xr-xscripts/attachment-data.pl127
1 files changed, 65 insertions, 62 deletions
diff --git a/scripts/attachment-data.pl b/scripts/attachment-data.pl
index 4a3a1b414..3599ace91 100755
--- a/scripts/attachment-data.pl
+++ b/scripts/attachment-data.pl
@@ -13,9 +13,13 @@ use File::Basename;
use File::Spec;
BEGIN {
- require lib;
- my $dir = File::Spec->rel2abs( File::Spec->catdir( dirname(__FILE__), '..' ) );
- lib->import( $dir, File::Spec->catdir( $dir, 'lib' ), File::Spec->catdir( $dir, qw(local lib perl5) ) );
+ require lib;
+ my $dir = File::Spec->rel2abs(File::Spec->catdir(dirname(__FILE__), '..'));
+ lib->import(
+ $dir,
+ File::Spec->catdir($dir, 'lib'),
+ File::Spec->catdir($dir, qw(local lib perl5))
+ );
}
use Bugzilla;
@@ -31,85 +35,84 @@ BEGIN { Bugzilla->extensions }
Bugzilla->usage_mode(USAGE_MODE_CMDLINE);
my ($help, $file);
-GetOptions(
- 'help|h' => \$help,
- 'file|f=s' => \$file,
-);
+GetOptions('help|h' => \$help, 'file|f=s' => \$file,);
pod2usage(1) if $help || !$file;
my $archive = Bugzilla::Attachment::Archive->new(file => $file);
my $cmd = shift @ARGV;
if ($cmd eq 'export') {
- while ( my $attach_id = <ARGV> ) {
- chomp $attach_id;
- my $attachment = Bugzilla::Attachment->new($attach_id);
- unless ($attachment) {
- warn "No attachment: $attach_id\n";
- next;
- }
- warn "writing $attach_id\n";
- $archive->write_attachment($attachment);
+ while (my $attach_id = <ARGV>) {
+ chomp $attach_id;
+ my $attachment = Bugzilla::Attachment->new($attach_id);
+ unless ($attachment) {
+ warn "No attachment: $attach_id\n";
+ next;
}
- $archive->write_checksum;
+ warn "writing $attach_id\n";
+ $archive->write_attachment($attachment);
+ }
+ $archive->write_checksum;
}
elsif ($cmd eq 'import') {
- while ( my $mem = $archive->read_member ) {
- warn "read $mem->{attach_id}\n";
+ while (my $mem = $archive->read_member) {
+ warn "read $mem->{attach_id}\n";
- my $attachment = Bugzilla::Attachment->new($mem->{attach_id});
- next unless $mem->{data_len};
- next unless check_attachment($attachment, $mem->{bug_id}, $mem->{data_len});
+ my $attachment = Bugzilla::Attachment->new($mem->{attach_id});
+ next unless $mem->{data_len};
+ next unless check_attachment($attachment, $mem->{bug_id}, $mem->{data_len});
- Bugzilla::Attachment::current_storage()->store( $attachment->id, $mem->{data} );
- }
+ Bugzilla::Attachment::current_storage()->store($attachment->id, $mem->{data});
+ }
}
elsif ($cmd eq 'check') {
- while ( my $mem = $archive->read_member() ) {
- warn "checking $mem->{attach_id}\n";
- my $attachment = Bugzilla::Attachment->new($mem->{attach_id});
- next unless $mem->{data_len};
- die "bad attachment\n" unless check_attachment($attachment, $mem->{bug_id}, $mem->{data_len});
- }
+ while (my $mem = $archive->read_member()) {
+ warn "checking $mem->{attach_id}\n";
+ my $attachment = Bugzilla::Attachment->new($mem->{attach_id});
+ next unless $mem->{data_len};
+ die "bad attachment\n"
+ unless check_attachment($attachment, $mem->{bug_id}, $mem->{data_len});
+ }
}
elsif ($cmd eq 'remove') {
- my %remove_ok;
- while ( my $mem = $archive->read_member ) {
- warn "checking $mem->{attach_id}\n";
-
- my $attachment = Bugzilla::Attachment->new($mem->{attach_id});
- die "bad attachment\n" unless check_attachment($attachment, $mem->{bug_id}, $mem->{data_len});
- $remove_ok{$mem->{attach_id}} = 1;
+ my %remove_ok;
+ while (my $mem = $archive->read_member) {
+ warn "checking $mem->{attach_id}\n";
+
+ my $attachment = Bugzilla::Attachment->new($mem->{attach_id});
+ die "bad attachment\n"
+ unless check_attachment($attachment, $mem->{bug_id}, $mem->{data_len});
+ $remove_ok{$mem->{attach_id}} = 1;
+ }
+ while (my $attach_id = <ARGV>) {
+ chomp $attach_id;
+ if ($remove_ok{$attach_id}) {
+ warn "removing $attach_id\n";
+ Bugzilla::Attachment::current_storage()->remove($attach_id);
}
- while ( my $attach_id = <ARGV> ) {
- chomp $attach_id;
- if ($remove_ok{$attach_id}) {
- warn "removing $attach_id\n";
- Bugzilla::Attachment::current_storage()->remove( $attach_id );
- }
- else {
- warn "Unable to remove $attach_id, as it did not occur in the archive.\n";
- }
+ else {
+ warn "Unable to remove $attach_id, as it did not occur in the archive.\n";
}
+ }
}
sub check_attachment {
- my ($attachment, $bug_id, $data_len) = @_;
-
- unless ($attachment) {
- warn "No attachment found. Skipping record.\n";
- return 0;
- }
- unless ( $attachment->bug_id == $bug_id ) {
- warn 'Wrong bug id (should be ' . $attachment->bug_id . ")\n";
- return 0;
- }
- unless ( $attachment->datasize == $data_len ) {
- warn 'Wrong size (should be ' . $attachment->datasize . ")\n";
- return 0;
- }
-
- return 1;
+ my ($attachment, $bug_id, $data_len) = @_;
+
+ unless ($attachment) {
+ warn "No attachment found. Skipping record.\n";
+ return 0;
+ }
+ unless ($attachment->bug_id == $bug_id) {
+ warn 'Wrong bug id (should be ' . $attachment->bug_id . ")\n";
+ return 0;
+ }
+ unless ($attachment->datasize == $data_len) {
+ warn 'Wrong size (should be ' . $attachment->datasize . ")\n";
+ return 0;
+ }
+
+ return 1;
}