Ignore:
Timestamp:
1999-10-19T16:21:35+13:00 (25 years ago)
Author:
davidb
Message:

Support functions to help with the generation of webpages from
Perl CGI scripts.

File:
1 edited

Legend:

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

    r619 r721  
    4040    if (!-e $file) {
    4141        print STDERR "util::rm $file does not exist\n";
    42     } elsif (!-f $file) {
    43         print STDERR "util::rm $file is not a regular file\n";
     42    } elsif ((!-f $file) && (!-l $file)) {
     43        print STDERR "util::rm $file is not a regular (or symbolic) file\n";
    4444    } else {
    4545        push (@filefiles, $file);
     
    6868        print STDERR "util::rm_r $file does not exist\n";
    6969
    70     } elsif (-d $file) {
     70    } elsif ((-d $file) && (!-l $file)) { # don't recurse down symbolic link
    7171        # get the contents of this directory
    7272        if (!opendir (INDIR, $file)) {
     
    9292}
    9393
     94# moves a file or a group of files
     95sub mv {
     96    my $dest = pop (@_);
     97    my (@srcfiles) = @_;
     98
     99    # remove trailing slashes from source and destination files
     100    $dest =~ s/[\\\/]+$//;
     101    map {$_ =~ s/[\\\/]+$//;} @srcfiles;
     102
     103    # a few sanity checks
     104    if (scalar (@srcfiles) == 0) {
     105    print STDERR "util::mv no destination directory given\n";
     106    return;
     107    } elsif ((scalar (@srcfiles) > 1) && (!-d $dest)) {
     108    print STDERR "util::mv if multiple source files are given the ".
     109        "destination must be a directory\n";
     110    return;
     111    }
     112
     113    # move the files
     114    foreach $file (@srcfiles) {
     115    my $tempdest = $dest;
     116    if (-d $tempdest) {
     117        my ($filename) = $file =~ /([^\\\/]+)$/;
     118        $tempdest .= "/$filename";
     119    }
     120    if (!-e $file) {
     121        print STDERR "util::mv $file does not exist\n";
     122    } else {
     123        rename ($file, $tempdest);
     124    }
     125    }
     126}
     127
    94128
    95129# copies a file or a group of files
     
    128162    }
    129163}
     164
    130165
    131166
     
    186221
    187222
     223sub mk_dir {
     224    my ($dir) = @_;
     225
     226    if (!mkdir ($dir, 0775)) {
     227    print STDERR "util::mk_dir could not create directory $dir\n";
     228    return;
     229    }
     230}
     231
    188232sub mk_all_dir {
    189233    my ($dir) = @_;
     
    239283    }
    240284   
     285}
     286
     287# make soft link to file if supported by OS, otherwise return error
     288sub soft_link {
     289    my ($src,$dest) = @_;
     290
     291    # remove trailing slashes from source and destination files
     292    $src =~ s/[\\\/]+$//;
     293    $dest =~ s/[\\\/]+$//;
     294
     295    # a few sanity checks
     296    if (!-e $src) {
     297    print STDERR "util::soft_link source file $src does not exist\n";
     298    return 0;
     299    }
     300
     301    my $dest_dir = &File::Basename::dirname($dest);
     302    mk_all_dir($dest_dir) if (!-e $dest_dir);
     303
     304    if (!symlink($src,$dest))
     305    {
     306    print STDERR "util::soft_link: unable to create soft link.";
     307    return 0;
     308    }
     309
     310    return 1;
    241311}
    242312
Note: See TracChangeset for help on using the changeset viewer.