Changeset 32844

Show
Ignore:
Timestamp:
04.03.2019 13:33:09 (6 months ago)
Author:
ak19
Message:

modified upgrade and downgrade dos filenames - getLong/ShortPathName don't work if the file doesn't exist on the file system. In this case, do the conversion on the directory, and then add the filename back on.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/util.pm

    r32791 r32844  
    863863    # Ensure any DOS-like filename, such as test~1.txt, has been upgraded 
    864864    # to its long (Windows) version 
    865     my $long_filename = Win32::GetLongPathName($filename_full_path); 
    866     if (defined $long_filename) { 
     865    # GetLongPathName doesn't work if the file doesn't exist - in this case, use the directory instead 
     866     
     867    if (-e $filename_full_path) { 
     868       my $long_filename = Win32::GetLongPathName($filename_full_path); 
     869       if (defined $long_filename) { 
    867870         
    868871        $filename_full_path = $long_filename; 
    869872    } 
     873    } else { 
     874      
     875       my ($tailname, $dirname, $suffix) 
     876            = &File::Basename::fileparse($filename_full_path, "\\.[^\\.]+\$"); 
     877        my $long_dirname = Win32::GetLongPathName($dirname); 
     878        if (defined $long_dirname) { 
     879        $filename_full_path = &FileUtils::filenameConcatenate($long_dirname, "$tailname$suffix"); 
     880        } 
     881    } 
     882     
    870883    # Make sure initial drive letter is lower-case (to fit in with rest of Greenstone) 
    871884    $filename_full_path =~ s/^(.):/\u$1:/; 
     
    889902    # Ensure the given long Windows filename is in a form that can 
    890903    # be opened by Perl => convert it to a short DOS-like filename 
    891  
     904    # GetShortPathName doesn't work if the file doesn't exist - in this case, use the directory instead 
     905        if (-e $filename_full_path) { 
    892906    my $short_filename = Win32::GetShortPathName($filename_full_path); 
    893907    if (defined $short_filename) { 
    894908        $filename_full_path = $short_filename; 
     909    } 
     910    } else { 
     911      my ($tailname, $dirname, $suffix) 
     912            = &File::Basename::fileparse($filename_full_path, "\\.[^\\.]+\$"); 
     913        my $short_dirname = Win32::GetShortPathName($dirname); 
     914        if (defined $short_dirname) { 
     915        $filename_full_path = &FileUtils::filenameConcatenate($short_dirname, "$tailname$suffix"); 
     916        } 
     917     
    895918    } 
    896919    # Make sure initial drive letter is lower-case (to fit in