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 >
Wrap
Text File
|
1992-03-10
|
1KB
|
73 lines
#! /usr/local/bin/perl
for ($i = 0; $i <= $#ARGV; $i++) {
open(FILE, $ARGV[$i]);
line:
while (<FILE>) {
chop;
($type, $uid, $gid, $mode, $name) = split;
$mode = oct($mode);
&create_dirs_as_needed(&basename($name));
if ($type eq "d") {
if (mkdir($name, $mode) == 0) {
printf(stderr "mkdir $name failed: $!\n");
if (chmod($mode, $name) != 1) {
printf(stderr "chmod $mode $name failed\n");
}
}
} else {
open(TMP, $name) ||
printf(stderr "can't create $name: $!\n");
close(TMP);
if (chmod($mode, $name) != 1) {
printf(stderr "chmod $mode $name failed\n");
}
}
if (chown($uid, $gid, $name) != 1) {
printf(stderr "chown $uid $gid $name failed\n");
}
}
}
sub basename {
local($path) = @_;
local(@elts);
@elts = split(/\//, $path);
pop(@elts);
return(join('/', @elts));
}
sub create_dirs_as_needed {
local($path) = @_;
local($base);
if (-f $path) {
printf(stderr "Yack, encountered a file named '%s' where we expected a directory.\n");
return;
}
if (-d $path) {
return;
}
$base = &basename($path);
&create_dirs_as_needed($base);
if (mkdir($path, 0755) == 0) {
printf(stderr "mkdir failed for '$path' in create_dirs_as_needed: $!\n");
}
}