ExtensionsLst.pm (86e1cf34) ExtensionsLst.pm (6eeb2f28)
1#**************************************************************
2#
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements. See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership. The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance

--- 454 unchanged lines hidden (view full) ---

463 return;
464 }
465
466 # Download the missing files.
467 for my $entry (@missing)
468 {
469 my ($protocol, $name, $URL, $md5sum) = @{$entry};
470
1#**************************************************************
2#
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements. See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership. The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance

--- 454 unchanged lines hidden (view full) ---

463 return;
464 }
465
466 # Download the missing files.
467 for my $entry (@missing)
468 {
469 my ($protocol, $name, $URL, $md5sum) = @{$entry};
470
471 # Open a .part file for writing.
472 my $filename = File::Spec->catfile($download_path, $name);
473 my $temporary_filename = $filename . ".part";
474 print "downloading to $temporary_filename\n";
475 open my $out, ">$temporary_filename";
476 binmode($out);
471 system(
472 $ENV{'JAVAINTERPRETER'},
473 "-cp",
474 File::Spec->catfile(
475 File::Spec->catfile($ENV{'SOLARENV'}, $ENV{'INPATH'}),
476 "class"),
477 "AOOJavaDownloader",
478 $name,
479 $URL,
480 'MD5',
481 $md5sum);
477
482
478 # Prepare md5
479 my $md5 = Digest::MD5->new();
480
481 # Download the extension.
482 my $agent = LWP::UserAgent->new();
483 $agent->timeout(120);
484 $agent->show_progress(1);
485 my $last_was_redirect = 0;
486 $agent->add_handler('response_redirect'
487 => sub{
488 $last_was_redirect = 1;
489 return;
490 });
491 $agent->add_handler('response_data'
492 => sub{
493 if ($last_was_redirect)
494 {
495 $last_was_redirect = 0;
496 # Throw away the data we got so far.
497 $md5->reset();
498 close $out;
499 open $out, ">$temporary_filename";
500 binmode($out);
501 }
502 my($response,$agent,$h,$data)=@_;
503 print $out $data;
504 $md5->add($data);
505 });
506 my $response = $agent->get($URL);
507 close $out;
508
509 # When download was successful then check the md5 checksum and rename the .part file
510 # into the actual extension name.
511 if ($response->is_success())
483 if ($? != 0)
512 {
484 {
513 if (defined $md5sum && length($md5sum)==32)
514 {
515 my $file_md5 = $md5->hexdigest();
516 if ($md5sum eq $file_md5)
517 {
518 print "md5 is OK\n";
519 }
520 else
521 {
522 unlink($temporary_filename) if ! $Debug;
523 die "downloaded file has the wrong md5 checksum: $file_md5 instead of $md5sum";
524 }
525 }
526 else
527 {
528 print "md5 is not present\n";
529 printf " is %s, length is %d\n", $md5sum, length(md5sum);
530 }
531
532 rename($temporary_filename, $filename) || die "can not rename $temporary_filename to $filename";
533 }
534 else
535 {
536 die "failed to download $URL";
537 }
538 }
539}
540
541
542
543

--- 79 unchanged lines hidden ---
485 die "failed to download $URL";
486 }
487 }
488}
489
490
491
492

--- 79 unchanged lines hidden ---