Changeset 14221


Ignore:
Timestamp:
2007-07-07T11:30:17+12:00 (17 years ago)
Author:
qq6
Message:

making hardlink works on windows. Many thanks to Pongtawat Chippimolchai

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/perllib/util.pm

    r14175 r14221  
    2626package util;
    2727
     28BEGIN {                                                             
     29    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};       
     30    die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};           
     31    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");                     
     32    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");               
     33}                                                                   
    2834use File::Copy;
    2935use File::Basename;
    30 
     36#use Win32::Hardlink;
    3137
    3238# removes files (but not directories)
     
    381387    # link not supported on windows 9x
    382388    if (($ENV{'GSDLOS'} =~ /^windows$/i) && (Win32::FsType() !~ /^ntfs$/i)) {
     389    print STDERR "util::hard_link: win32: using copy for hard link.\n";
    383390    &File::Copy::copy ($src, $dest);
    384391
     
    407414    my $dest_dir = &File::Basename::dirname($dest);
    408415    mk_all_dir($dest_dir) if (!-e $dest_dir);
    409 
     416       
     417    # symlink not supported on windows
    410418    if ($ENV{'GSDLOS'} =~ /^windows$/i) {
    411     # symlink not supported on windows
    412     &File::Copy::copy ($src, $dest);
     419     
     420        if ( (Win32::FsType() =~ /^ntfs$/i) &&
     421            ($src =~ /^.:\\.*/) && ($dest =~ /^.:\\.*/) &&
     422            (substr($src,0,3) eq substr($dest,0,3)) ) {
     423       
     424            # if filesystem is NTFS and both source and destination is on the same local drive,
     425            # use hardlink instead of symlink
     426            #print STDERR "util::soft_link: win32: using hard link instead of soft ink.\n";
     427        require Win32::Hardlink;
     428        hard_link($src,$dest);
     429        } else {
     430            #print STDERR "util::soft_link: win32: using copy for soft link.\n ";
     431            &File::Copy::copy ($src, $dest);
     432        }
    413433
    414434    } elsif (!eval {symlink($src, $dest)}) {
Note: See TracChangeset for help on using the changeset viewer.