Changeset 23758 for main/trunk
- Timestamp:
- 2011-03-02T16:13:39+13:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/dbutil/gdbm.pm
r23399 r23758 158 158 159 159 160 sub set_infodb_entry 160 sub set_infodb_entry_OLD 161 161 { 162 162 my $infodb_file_path = shift(@_); … … 164 164 my $infodb_map = shift(@_); 165 165 166 # Protect metadtaa values that go inside quotes for gdbmset166 # Protect metadata values that go inside quotes for gdbmset 167 167 foreach my $k (keys %$infodb_map) { 168 168 my @escaped_v = (); … … 184 184 # Generate the record string 185 185 my $serialized_infodb_map = &dbutil::convert_infodb_hash_to_string($infodb_map); 186 ##print STDERR "**** ser dr\n$serialized_infodb_map\n\n\n";186 ## print STDERR "**** ser dr\n$serialized_infodb_map\n\n\n"; 187 187 188 188 # Store it into GDBM 189 189 my $cmd = "gdbmset \"$infodb_file_path\" \"$infodb_key\" \"$serialized_infodb_map\""; 190 190 my $status = system($cmd); 191 192 return $status; 191 193 192 return $status; 194 } 195 196 197 198 sub set_infodb_entry 199 { 200 my $infodb_file_path = shift(@_); 201 my $infodb_key = shift(@_); 202 my $infodb_map = shift(@_); 193 203 204 # HTML escape anything that is not part of the "contains" metadata value 205 foreach my $k (keys %$infodb_map) { 206 my @escaped_v = (); 207 foreach my $v (@{$infodb_map->{$k}}) { 208 if ($k eq "contains") { 209 push(@escaped_v, $v); 210 } 211 else { 212 my $ev = &ghtml::unescape_html($v); 213 push(@escaped_v, $ev); 214 } 215 } 216 $infodb_map->{$k} = \@escaped_v; 217 } 218 219 # Generate the record string 220 my $serialized_infodb_map = &dbutil::convert_infodb_hash_to_string($infodb_map); 221 ### print STDERR "**** ser dr\n$serialized_infodb_map\n\n\n"; 222 223 # Store it into GDBM using 'txt2db -append' which despite its name 224 # actually replaces the record if it already exists 225 226 my $cmd = "txt2db -append \"$infodb_file_path\""; 227 228 my $status = undef; 229 if(!open(GOUT, "| $cmd")) 230 { 231 print STDERR "Error: gdbm::set_infodb_entry() failed to open pipe to: $cmd\n"; 232 print STDERR " $!\n"; 233 $status = -1; 234 } 235 else { 236 binmode(GOUT,":utf8"); 237 238 print GOUT "[$infodb_key]\n"; 239 print GOUT "$serialized_infodb_map\n"; 240 241 close(GOUT); 242 $status = 0; # as in exit status of cmd OK 243 } 244 245 return $status; 194 246 } 195 247
Note:
See TracChangeset
for help on using the changeset viewer.