Changeset 24932
- Timestamp:
- 2012-01-10T16:18:19+13:00 (12 years ago)
- Location:
- main/trunk/greenstone2/perllib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/plugins/DirectoryPlugin.pm
r24829 r24932 382 382 $dirname = &util::filename_cat ($base_dir, $file) if $base_dir =~ /\w/; 383 383 } 384 384 385 385 my $directory_ok = $self->check_directory_path($dirname); 386 386 return $directory_ok unless (defined $directory_ok && $directory_ok == 1); … … 424 424 425 425 426 426 my $os_dirsep = &util::get_os_dirsep(); 427 427 my $dirsep = &util::get_dirsep(); 428 428 my $base_dir_regexp = $base_dir; 429 429 $base_dir_regexp =~ s/\//$os_dirsep/g; 430 my $local_dirname = $dirname; 431 432 $local_dirname =~ s/^$base_dir_regexp($os_dirsep)*//; 430 431 # Want to get relative path of local_dirname within the base_directory 432 # but with URL style slashes. 433 my $local_dirname = &util::filename_within_directory_url_format($dirname, $base_dir); 434 433 435 # if we are in import folder, then local_dirname will be empty 434 436 if ($local_dirname ne "") { 435 # look for extra metadata passed down from higher folders 436 $local_dirname .= $dirsep;437 # look for extra metadata passed down from higher folders 438 $local_dirname .= "/"; # closing slash must be URL type slash also and not $dirsep; 437 439 if (defined $self->{'subdir_extrametakeys'}->{$local_dirname}) { 438 440 my $extrakeys = $self->{'subdir_extrametakeys'}->{$local_dirname}; … … 491 493 492 494 my $subdir_extrametakeys = $self->{'subdir_extrametakeys'}; 493 495 494 496 my $subdir_rec = { 're' => $subdir_re, 'md' => $md, 'mf' => $mf }; 495 497 -
main/trunk/greenstone2/perllib/util.pm
r24874 r24932 845 845 $filename =~ s@\(@\\(@g; # escape brackets 846 846 $filename =~ s@\)@\\)@g; # escape brackets 847 $filename =~ s@\[@\\[@g; # escape brackets 848 $filename =~ s@\]@\\]@g; # escape brackets 847 849 848 850 return $filename; … … 857 859 $filename =~ s@\\\(@(@g; # remove RE syntax for ( => "\(" turns into "(" 858 860 $filename =~ s@\\\)@)@g; # remove RE syntax for ) => "\)" turns into ")" 861 $filename =~ s@\\\[@[@g; # remove RE syntax for [ => "\[" turns into "[" 862 $filename =~ s@\\\]@]@g; # remove RE syntax for ] => "\]" turns into "]" 859 863 return $filename; 860 864 } … … 1032 1036 } 1033 1037 1034 1038 # If filename is relative to within_dir, returns the relative path of filename to that directory 1039 # with slashes in the filename returned as they were in the original (absolute) filename. 1035 1040 sub filename_within_directory 1036 1041 { … … 1049 1054 return $filename; 1050 1055 } 1056 1057 # If filename is relative to within_dir, returns the relative path of filename to that directory in URL format. 1058 # Filename and within_dir can be any type of slashes, but will be compared as URLs (i.e. unix-style slashes). 1059 # The subpath returned will also be a URL type filename. 1060 sub filename_within_directory_url_format 1061 { 1062 my ($filename,$within_dir) = @_; 1063 1064 # convert parameters only to / slashes if Windows 1065 1066 my $filename_urlformat = $filename; 1067 my $within_dir_urlformat = $within_dir; 1068 1069 if ($ENV{'GSDLOS'} =~ /^windows$/i) { 1070 # Only need to worry about Windows, as Unix style directories already in url-format 1071 # Convert Windows style \ => / 1072 $filename_urlformat =~ s@\\@/@g; 1073 $within_dir_urlformat =~ s@\\@/@g; 1074 } 1075 1076 #if ($within_dir_urlformat !~ m/\/$/) { 1077 # make sure directory ends with a slash 1078 #$within_dir_urlformat .= "/"; 1079 #} 1080 1081 my $within_dir_urlformat_re = &filename_to_regex($within_dir_urlformat); # escape any special RE characters, such as brackets 1082 1083 #print STDERR "@@@@@ $filename_urlformat =~ $within_dir_urlformat_re\n"; 1084 1085 # dir prefix may or may not end with a slash (this is discarded when extracting the sub-filepath) 1086 if ($filename_urlformat =~ m/^$within_dir_urlformat_re(?:\/)*(.*)$/) { 1087 $filename_urlformat = $1; 1088 } 1089 1090 return $filename_urlformat; 1091 } 1092 1051 1093 1052 1094 sub filename_within_collection
Note:
See TracChangeset
for help on using the changeset viewer.