Changeset 493


Ignore:
Timestamp:
Apr 27, 2010, 9:39:02 AM (10 years ago)
Author:
lucas
Message:

couch-dump: use LWP::Simple instead of system(wget) (closes #14)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • couchdb/couch-dump

    r492 r493  
    2424use DB::CouchDB;
    2525use Data::Dumper;
     26use LWP::Simple qw($ua getstore is_error);
     27$LWP::Simple::ua->agent('couchdb-dump/0.2');
    2628
    2729sub usage {
     
    7779my $attachments;
    7880my $attachment_url;
     81my $http_status;
    7982
    8083while (my $id = $list->next_key() ) {
     
    8992    chdir '_design';
    9093    $doc_url = "http://$hostname:$port/$db_name/$id";
    91     `wget -q $doc_url -O design_$1`;
     94    $http_status = getstore($doc_url, "design_$1");
     95    if (is_error($http_status)) {
     96      # print error but don't quit
     97      print STDERR "\nError fetching design document '$id', HTTP code $http_status\n";
     98    }
    9299    chdir '..';
    93100    # skip the rest of the loop
     
    98105  # Dump the document
    99106  $doc_url = "http://$hostname:$port/$db_name/$id";
    100   `wget -q $doc_url -O doc_$id`;
     107  $http_status = getstore($doc_url, "doc_$id");
     108  if (is_error($http_status)) {
     109    # print error but don't quit
     110    print STDERR "\nError fetching document '$id', HTTP code $http_status\n";
     111  }
    101112
    102113  # Dump attachments (if any)
     
    110121      chdir $id;
    111122      $attachment_url = "http://$hostname:$port/$db_name/$id/$attachment";
    112       `wget -q $attachment_url`;
     123      $http_status = getstore($attachment_url, "$attachment");
     124      if (is_error($http_status)) {
     125        # print error but don't quit
     126        print STDERR "\nError fetching attachment '$id', HTTP code $http_status\n";
     127      }
    113128      chdir '..';
    114129    }
Note: See TracChangeset for help on using the changeset viewer.