ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Utilities/AddDir.pm
Revision: 1.8
Committed: Wed Feb 2 11:10:18 2005 UTC (20 years, 3 months ago) by sashby
Content type: text/plain
Branch: MAIN
Changes since 1.7: +48 -0 lines
Log Message:
Bugfix: add copy with skip for certain files. Faster dev area creation.

File Contents

# User Rev Content
1 williamc 1.1 package AddDir;
2 williamc 1.2 require 5.001;
3 williamc 1.1 require Exporter;
4     use Cwd;
5     @ISA = qw(Exporter);
6 williamc 1.4 @EXPORT = qw(adddir copydir);
7    
8 williamc 1.1
9 williamc 1.3 sub adddir {
10 williamc 1.1 my $indir=shift;
11     my $startdir=cwd;
12     my @dir=split /\//, $indir;
13    
14     if ( $indir=~/^\// ) {
15     chdir "/";
16     shift @dir;
17     }
18     umask 02;
19     foreach $dirname ( @dir ) {
20     next if ( $dirname eq "" );
21     if ( ! -e $dirname ) {
22     mkdir ( $dirname , 0775) ||
23     die "cannot make directory ".$dirname." $!\n";
24     print $i." ".$dirname."\n" if $debug;
25     }
26     chdir $dirname;
27     }
28     chdir $startdir;
29 williamc 1.4 }
30    
31 sashby 1.6 sub copydir
32     {
33     my $src=shift;
34     my $dest=shift;
35    
36     use DirHandle;
37     use File::Copy;
38    
39     adddir($dest);
40     my $dh=DirHandle->new($src);
41    
42     if (defined $dh)
43     {
44     my @allfiles=$dh->read();
45    
46     my $file;
47     foreach $file ( @allfiles )
48     {
49 williamc 1.4 next if $file=~/^\.\.?/;
50 sashby 1.6 if ( -d $src."/".$file )
51     {
52     copydir($src."/".$file,$dest."/".$file);
53     }
54     else
55     {
56     copy($src."/".$file,$dest."/".$file);
57 sashby 1.7 if ( -x $src."/".$file || -X $src."/".$file ) {chmod(0775,$dest."/".$file);}
58 sashby 1.6 }
59 williamc 1.4 }
60 sashby 1.6 undef $dh;
61     }
62     else
63     {
64     die "Attempt to open a non-existent directory ($src). Exitting\n";
65     }
66     }
67 sashby 1.8
68     sub copydirwithskip
69     {
70     my $src=shift;
71     my $dest=shift;
72     my ($filetoskip)=@_;
73    
74     use DirHandle;
75     use File::Copy;
76    
77     adddir($dest);
78    
79     my $dh=DirHandle->new($src);
80    
81     if (defined $dh)
82     {
83     my @allfiles=$dh->read();
84    
85     my $file;
86     foreach $file ( @allfiles )
87     {
88     next if $file=~/^\.\.?/;
89     # Skip backup files and x~ files:
90     next if $file =~ /.*bak$/;
91     next if $file =~ /.*~$/;
92    
93     if ($file eq $filetoskip)
94     {
95     next;
96     }
97    
98     if ( -d $src."/".$file )
99     {
100     copydir($src."/".$file,$dest."/".$file);
101     }
102     else
103     {
104     copy($src."/".$file,$dest."/".$file);
105     if ( -x $src."/".$file || -X $src."/".$file ) {chmod(0775,$dest."/".$file);}
106     }
107     }
108     undef $dh;
109     }
110     else
111     {
112     die "Attempt to open a non-existent directory ($src). Exitting\n";
113     }
114     }