home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / cops_104.zip / cops_104 / kuang.pl.shar / put-cf < prev    next >
Text File  |  1992-03-10  |  1KB  |  73 lines

  1. #! /usr/local/bin/perl
  2.  
  3. for ($i = 0; $i <= $#ARGV; $i++) {
  4.     open(FILE, $ARGV[$i]);
  5.  
  6.   line:
  7.     while (<FILE>) {
  8.     chop;
  9.     ($type, $uid, $gid, $mode, $name) = split;
  10.     $mode = oct($mode);
  11.  
  12.     &create_dirs_as_needed(&basename($name));
  13.  
  14.     if ($type eq "d") {
  15.         if (mkdir($name, $mode) == 0) {
  16.         printf(stderr "mkdir $name failed: $!\n");
  17.         if (chmod($mode, $name) != 1) {
  18.             printf(stderr "chmod $mode $name failed\n");
  19.         }
  20.         }
  21.  
  22.     } else {
  23.         open(TMP, $name) ||
  24.           printf(stderr "can't create $name: $!\n");
  25.         
  26.         close(TMP);
  27.  
  28.         if (chmod($mode, $name) != 1) {
  29.         printf(stderr "chmod $mode $name failed\n");
  30.         }
  31.     }
  32.  
  33.     if (chown($uid, $gid, $name) != 1) {
  34.         printf(stderr "chown $uid $gid $name failed\n");
  35.     }
  36.     }
  37. }
  38.  
  39. sub basename {
  40.     local($path) = @_;
  41.     local(@elts);
  42.  
  43.     @elts = split(/\//, $path);
  44.     pop(@elts);
  45.     return(join('/', @elts));
  46. }
  47.  
  48.     
  49. sub create_dirs_as_needed {
  50.     local($path) = @_;
  51.     local($base);
  52.  
  53.     if (-f $path) {
  54.     printf(stderr "Yack, encountered a file named '%s' where we expected a directory.\n");
  55.     return;
  56.     }
  57.  
  58.     if (-d $path) {
  59.     return;
  60.     }
  61.  
  62.     $base = &basename($path);
  63.  
  64.     &create_dirs_as_needed($base);
  65.  
  66.     if (mkdir($path, 0755) == 0) {
  67.     printf(stderr "mkdir failed for '$path' in create_dirs_as_needed: $!\n");
  68.     }
  69. }
  70.  
  71.     
  72.     
  73.