- Timestamp:
- 1999-12-13T16:53:21+13:00 (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/docsave.pm
r810 r834 40 40 41 41 sub new { 42 my ($class, $collection, $archive_info, $verbosity, $gzip) = @_;42 my ($class, $collection,$archive_info,$verbosity,$gzip,$groupsize) = @_; 43 43 my $self = new docproc (); 44 44 … … 47 47 $self->{'verbosity'} = $verbosity; 48 48 $self->{'gzip'} = $gzip; 49 $self->{'groupsize'} = $groupsize; 50 $self->{'gs_count'} = 0; 49 51 50 52 # set a default for the archive directory … … 69 71 $OID = "NULL" unless defined $OID; 70 72 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); 79 76 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"; 89 122 } 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 } 95 124 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; 113 144 } 114 145 } 115 146 116 147 # 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()); 119 149 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 153 sub close_file_output 154 { 155 my ($self) = @_; 156 125 157 close OUTDOC; 126 158 159 my $OID = $self->{'gs_OID'}; 160 my $short_doc_file = $self->{'gs_short_filename'}; 161 127 162 if ($self->{'gzip'}) { 163 my $doc_file = $self->{'gs_filename'}; 128 164 `gzip $doc_file`; 129 165 $doc_file .= ".gz"; … … 131 167 if (!-e $doc_file) { 132 168 print STDERR "error while gzipping: $doc_file doesn't exist\n"; 133 return ;169 return 0; 134 170 } 135 171 } … … 137 173 # store reference in the archive_info 138 174 $self->{'archive_info'}->add_info($OID, $short_doc_file); 139 175 176 return 1; 140 177 } 141 178 142 143 179 1;
Note:
See TracChangeset
for help on using the changeset viewer.