Changeset 834 for trunk


Ignore:
Timestamp:
1999-12-13T16:53:21+13:00 (24 years ago)
Author:
davidb
Message:

'groupsize' added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/docsave.pm

    r810 r834  
    4040
    4141sub new {
    42     my ($class, $collection, $archive_info, $verbosity, $gzip) = @_;
     42    my ($class, $collection,$archive_info,$verbosity,$gzip,$groupsize) = @_;
    4343    my $self = new docproc ();
    4444
     
    4747    $self->{'verbosity'} = $verbosity;
    4848    $self->{'gzip'} = $gzip;
     49    $self->{'groupsize'} = $groupsize;
     50    $self->{'gs_count'} = 0;
    4951
    5052    # set a default for the archive directory
     
    6971    $OID = "NULL" unless defined $OID;
    7072
    71     # get the document's directory.
    72     my $doc_info = $self->{'archive_info'}->get_info($OID);
    73     my $doc_dir = "";
    74     if (defined $doc_info && scalar(@$doc_info) >= 1) {
    75     # this OID already has an assigned directory, use the
    76     # same one.
    77     $doc_dir = $doc_info->[0];
    78     $doc_dir =~ s/\/?doc\.gml(\.gz)?$//;
     73    my $groupsize = $self->{'groupsize'};
     74    my $gs_count = $self->{'gs_count'};
     75    my $open_new_file = (($gs_count % $groupsize)==0);
    7976
    80     } else {
    81     # have to get a new document directory
    82     my $doc_dir_rest = $OID;
    83     my $doc_dir_num = 0;
    84     do {
    85         $doc_dir .= "/" if $doc_dir_num > 0;
    86         if ($doc_dir_rest =~ s/^(.{1,8})//) {
    87         $doc_dir .= $1;
    88         $doc_dir_num++;
     77    # opening a new file, or document has assoicated files => directory needed
     78    if (($open_new_file) || (scalar(@{$doc_obj->get_assoc_files()})>0))
     79    {
     80    # get the document's directory.
     81    my $doc_info = $self->{'archive_info'}->get_info($OID);
     82    my $doc_dir = "";
     83    if (defined $doc_info && scalar(@$doc_info) >= 1) {
     84        # this OID already has an assigned directory, use the
     85        # same one.
     86        $doc_dir = $doc_info->[0];
     87        $doc_dir =~ s/\/?doc\.gml(\.gz)?$//;
     88    } else {
     89        # have to get a new document directory
     90        my $doc_dir_rest = $OID;
     91        my $doc_dir_num = 0;
     92        do {
     93        $doc_dir .= "/" if $doc_dir_num > 0;
     94        if ($doc_dir_rest =~ s/^(.{1,8})//) {
     95            $doc_dir .= $1;
     96            $doc_dir_num++;
     97        }
     98        } while ($doc_dir_rest ne "" &&
     99             ((-d &util::filename_cat ($archive_dir, "$doc_dir.dir")) ||
     100              ($self->{'archive_info'}->size() >= 1024 && $doc_dir_num < 2)));
     101        $doc_dir .= ".dir";
     102       
     103    }
     104   
     105    &util::mk_all_dir ("$archive_dir/$doc_dir");
     106   
     107    # copy all the associated files, add this information as metadata
     108    # to the document
     109    my @assoc_files = ();
     110    foreach $assoc_file (@{$doc_obj->get_assoc_files()}) {
     111        my ($dir, $afile) = $assoc_file->[1] =~ /^(.*?)([^\/\\]+)$/;
     112        $dir = "" unless defined $dir;
     113        if (-e $assoc_file->[0]) {
     114        my $filepath = &util::filename_cat($archive_dir, $doc_dir, $afile);
     115        &util::hard_link ($assoc_file->[0], $filepath);
     116        $doc_obj->add_metadata ($doc_obj->get_top_section(),
     117                    "gsdlassocfile",
     118                    "$afile:$assoc_file->[2]:$dir");
     119        } else {
     120        print STDERR "docsave::process couldn't copy the associated file " .
     121            "$assoc_file->[0] to $afile\n";
    89122        }
    90     } while ($doc_dir_rest ne "" &&
    91          ((-d &util::filename_cat ($archive_dir, "$doc_dir.dir")) ||
    92           ($self->{'archive_info'}->size() >= 1024 && $doc_dir_num < 2)));
    93     $doc_dir .= ".dir";
    94     }
     123    }
    95124
    96     &util::mk_all_dir ("$archive_dir/$doc_dir");
    97 
    98     # copy all the associated files, add this information as metadata
    99     # to the document
    100     my @assoc_files = ();
    101     foreach $assoc_file (@{$doc_obj->get_assoc_files()}) {
    102     my ($dir, $afile) = $assoc_file->[1] =~ /^(.*?)([^\/\\]+)$/;
    103     $dir = "" unless defined $dir;
    104     if (-e $assoc_file->[0]) {
    105         my $filepath = &util::filename_cat($archive_dir, $doc_dir, $afile);
    106         &util::hard_link ($assoc_file->[0], $filepath);
    107         $doc_obj->add_metadata ($doc_obj->get_top_section(),
    108                     "gsdlassocfile",
    109                     "$afile:$assoc_file->[2]:$dir");
    110     } else {
    111         print STDERR "docsave::process couldn't copy the associated file " .
    112         "$assoc_file->[0] to $afile\n";
     125    if ($open_new_file)
     126    {
     127        # only if opening new file
     128        my $doc_file
     129        = &util::filename_cat ($archive_dir, $doc_dir, "doc.gml");
     130        my $short_doc_file = &util::filename_cat ($doc_dir, "doc.gml");
     131       
     132        if ($gs_count>0)
     133        {
     134        return if (!$self->close_file_output());
     135        }
     136       
     137        if (!open (OUTDOC, ">$doc_file")) {
     138        print STDERR "docsave::process could not write to file $docfile\n";
     139        return;
     140        }
     141        $self->{'gs_filename'} = $doc_file;
     142        $self->{'gs_short_filename'} = $short_doc_file;
     143        $self->{'gs_OID'} = $OID;
    113144    }
    114145    }
    115146
    116147    # save this document
    117     my $doc_file = &util::filename_cat ($archive_dir, $doc_dir, "doc.gml");
    118     my $short_doc_file = &util::filename_cat ($doc_dir, "doc.gml");
     148    $doc_obj->output_section('docsave::OUTDOC', $doc_obj->get_top_section());
    119149
    120     if (!open (OUTDOC, ">$doc_file")) {
    121     print STDERR "docsave::process could not write to file $docfile\n";
    122     return;
    123     }
    124     $doc_obj->output_section('docsave::OUTDOC', $doc_obj->get_top_section());
     150    $self->{'gs_count'}++;
     151}
     152
     153sub close_file_output
     154{
     155    my ($self) = @_;
     156
    125157    close OUTDOC;
    126158
     159    my $OID = $self->{'gs_OID'};
     160    my $short_doc_file = $self->{'gs_short_filename'};
     161
    127162    if ($self->{'gzip'}) {
     163    my $doc_file = $self->{'gs_filename'};
    128164    `gzip $doc_file`;
    129165    $doc_file .= ".gz";
     
    131167    if (!-e $doc_file) {
    132168        print STDERR "error while gzipping: $doc_file doesn't exist\n";
    133         return;
     169        return 0;
    134170    }
    135171    }
     
    137173    # store reference in the archive_info
    138174    $self->{'archive_info'}->add_info($OID, $short_doc_file);
    139    
     175
     176    return 1;
    140177}
    141178
    142 
    1431791;
Note: See TracChangeset for help on using the changeset viewer.