Changeset 721 for trunk/gsdl/perllib/util.pm
- Timestamp:
- 1999-10-19T16:21:35+13:00 (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/util.pm
r619 r721 40 40 if (!-e $file) { 41 41 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"; 44 44 } else { 45 45 push (@filefiles, $file); … … 68 68 print STDERR "util::rm_r $file does not exist\n"; 69 69 70 } elsif ( -d $file) {70 } elsif ((-d $file) && (!-l $file)) { # don't recurse down symbolic link 71 71 # get the contents of this directory 72 72 if (!opendir (INDIR, $file)) { … … 92 92 } 93 93 94 # moves a file or a group of files 95 sub 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 94 128 95 129 # copies a file or a group of files … … 128 162 } 129 163 } 164 130 165 131 166 … … 186 221 187 222 223 sub 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 188 232 sub mk_all_dir { 189 233 my ($dir) = @_; … … 239 283 } 240 284 285 } 286 287 # make soft link to file if supported by OS, otherwise return error 288 sub 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; 241 311 } 242 312
Note:
See TracChangeset
for help on using the changeset viewer.