Changeset 26964


Ignore:
Timestamp:
2013-02-26T11:45:53+13:00 (11 years ago)
Author:
jmt12
Message:

Altered to use util functions rather than built-in perl file tests. Also slight change to archives directory generation so that OIDs starting HASH are keep as prefixes... and to make path splitting only 3 characters long (which is, in theory, the longest you can have a hexidecimal string without potentially exhausting the number of subdirectories in file systems like EXT2/3 and NTFS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/parallel-building/trunk/src/perllib/plugouts/BasePlugout.pm

    r25120 r26964  
    508508            # only if opening new file
    509509        my $output_dir = $self->get_output_dir();
    510         &util::mk_all_dir ($output_dir) unless -e $output_dir;
     510        &util::mk_all_dir ($output_dir) unless &util::dir_exists($output_dir);
    511511        my $doc_file = &util::filename_cat ($output_dir, $doc_dir, "doc.xml");
    512512        my $short_doc_file = &util::filename_cat ($doc_dir, "doc.xml");
     
    614614   do {
    615615       $doc_dir .= "/" if $doc_dir_num > 0;
    616 #       if ($doc_dir_rest =~ s/^(.{1,8})//) {
    617        if ($doc_dir_rest =~ s/^(.{1,4})//) {
     616#       if ($doc_dir_rest =~ s/^((HASH)?.{1,3})//i) {
     617       if ($doc_dir_rest =~ s/^(.{1,3})//) {
    618618       $doc_dir .= $1;
    619619       $doc_dir_num++;
    620620       }
    621    } while ($doc_dir_rest ne "" &&
    622         ((-d &util::filename_cat ($working_dir, "$doc_dir.dir")) ||
    623          ($working_info->size() >= 1024 && $doc_dir_num < 2)));
     621   } while ($doc_dir_rest ne "" && ((&util::dir_exists(&util::filename_cat($working_dir, "$doc_dir.dir"))) || ($working_info->size() >= 1024 && $doc_dir_num < 2)));
    624622   my $i = 1;
    625623   my $doc_dir_base = $doc_dir;
    626    while (-d &util::filename_cat ($working_dir, "$doc_dir.dir")) {
     624   #rint "!! - ensure path is unique by adding numeric suffix if necessary\n";
     625   while (&util::dir_exists(&util::filename_cat($working_dir, "$doc_dir.dir"))) {
    627626       $doc_dir = "$doc_dir_base-$i";
    628627       $i++;
    629628   }
    630          
     629
    631630   return "$doc_dir.dir";
    632631}
     
    641640    return if (!defined $output_dir);
    642641
    643     &util::mk_all_dir ($output_dir) unless -e $output_dir;
     642    &util::mk_all_dir ($output_dir) unless &util::dir_exists($output_dir);
    644643     
    645644    my $working_dir = &util::filename_cat($output_dir, $doc_dir);
    646     &util::mk_all_dir ($working_dir) unless -e $working_dir;
     645    &util::mk_all_dir ($working_dir) unless &util::dir_exists($working_dir);
    647646
    648647    my @assoc_files = ();
     
    685684    $real_filename = &util::downgrade_if_dos_filename($real_filename);
    686685
    687     if (-e $real_filename) {
     686    if (&util::file_exists($real_filename)) {
    688687
    689688        $filename = &util::filename_cat($working_dir, $afile);
     
    732731    my $raw_filename = &util::downgrade_if_dos_filename($real_filename);
    733732
    734     if (-e $raw_filename) {
     733    if (&util::file_exists($raw_filename)) {
    735734
    736735#       if (defined $collect_dir) {
    737736#       my $collect_dir_re_safe = $collect_dir;
    738 #       $collect_dir_re_safe =~ s/\\/\\\\/g;
     737#       $collect_dir_re_safe =~ s/\\/\\\\/g; # use &util::filename_to_regex()
    739738#       $collect_dir_re_safe =~ s/\./\\./g;##
    740739
     
    805804
    806805    ##print STDERR "*** To set in db: \n\t$doc_db\n\t$oid\n\t$doc_db_text\n";
     806    if (($oid_files->{'index-status'} eq "I") || ($oid_files->{'index-status'} eq "R"))
     807    {
     808      my $top_section = $doc_obj->get_top_section();
     809      my $dc_titles = $doc_obj->get_metadata($top_section, 'dls.Title');
     810      my $dc_title = join("; ", @$dc_titles);
     811      # if we still don't have a title, use a feature I added into a doc_obj ages
     812      # ago to find *any* title (regardless of namespace) [jmt12]
     813      if ($dc_title eq '')
     814      {
     815        $dc_title = $doc_obj->get_metadata_element($top_section, 'Title', 1);
     816      }
     817      if ($oid_files->{'index-status'} eq "R")
     818      {
     819        $dc_title .= " (Updated)";
     820      }
     821      my $rss_filename = &util::filename_cat($output_dir,"rss-items.rdf");
     822      if (open(RSSOUT, &util::file_openfdcommand($rss_filename, '>>')))
     823      {
     824        print RSSOUT "<item>\n";
     825        print RSSOUT "   <title>" . $dc_title . "</title>\n";
     826        print RSSOUT "   <link>_httpdomain__httpcollection_/document/" . $doc_obj->get_OID() . "</link>\n";
     827        print RSSOUT "</item>\n";
     828        close(RSSOUT);
     829      }
     830      else
     831      {
     832        print STDERR "**** Failed to open " . $rss_filename . "\n";
     833        print STDERR $! . "\n";
     834      }
     835    }
    807836
    808837    $oid_files->{'doc-file'} = [ $oid_files->{'doc-file'} ];
     
    828857}
    829858
     859# /** @function append_to_rss_file()
     860#  */
     861sub append_to_rss_file
     862{
     863  my $self = shift(@_);
     864  my ($doc_obj, $index_status, $output_dir) = @_;
     865
     866}
     867# /** append_to_rss_file() **/
    830868
    831869sub set_sortmeta {
     
    849887    my ($output_file_name, $xslt_file)=@_;
    850888
    851     return unless defined $xslt_file and $xslt_file ne "" and -e $xslt_file;
     889    return unless defined $xslt_file and $xslt_file ne "" and &util::file_exists($xslt_file);
    852890   
    853891    my $java_class_path =  &util::filename_cat ($ENV{'GSDLHOME'},"bin","java","ApplyXSLT.jar");
     
    923961    $doc_file .= ".gz";
    924962    $short_doc_file .= ".gz";
    925     if (!-e $doc_file) {
     963    if (!&util::file_exists($doc_file)) {
    926964         my $outhandle = $self->{'output_handle'};
    927965        print $outhandle "error while gzipping: $doc_file doesn't exist\n";
Note: See TracChangeset for help on using the changeset viewer.