Ignore:
Timestamp:
1999-09-22T12:18:59+12:00 (25 years ago)
Author:
sjboddie
Message:

Added function to form hard link between two files
(used for handling images sensibly during building of

HTML pages)

File:
1 edited

Legend:

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

    r537 r619  
    2727
    2828use File::Copy;
     29use File::Basename;
    2930
    3031
     
    210211}
    211212
     213# make hard link to file if supported by OS, otherwise copy the file
     214sub hard_link {
     215    my ($src,$dest) = @_;
     216
     217    # remove trailing slashes from source and destination files
     218    $src =~ s/[\\\/]+$//;
     219    $dest =~ s/[\\\/]+$//;
     220
     221    # a few sanity checks
     222    if (!-e $src) {
     223    print STDERR "util::hard_link source file $src does not exist\n";
     224    return;
     225    }
     226    elsif (-d $src) {
     227    print STDERR "util::hard_link source $src is a directory\n";
     228    return;
     229    }
     230
     231    my $dest_dir = &File::Basename::dirname($dest);
     232    mk_all_dir($dest_dir) if (!-e $dest_dir);
     233
     234    if (!link($src,$dest))
     235    {
     236    print STDERR "util::hard_link: unable to create hard link. ";
     237    print STDERR " Attempting to copy file: $src -> $dest\n";
     238    &File::Copy::copy ($src, $dest);
     239    }
     240   
     241}
     242
     243
     244
    212245
    213246# updates a copy of a directory in some other part of the filesystem
     
    374407}
    375408
     409sub get_os_dirsep {
     410
     411    if ($ENV{'GSDLOS'} =~ /^windows$/i) {
     412    return "\\\\";
     413    } else {
     414    return "\\\/";
     415    }
     416}
     417
     418sub get_re_dirsep {
     419
     420    return "\\\\|\\\/";
     421}
     422
    376423
    377424# if this is running on windows we want binaries to end in
Note: See TracChangeset for help on using the changeset viewer.