1 package ExtUtils::Install;
5 @EXPORT = ('install','uninstall');
9 use ExtUtils::MakeMaker; # to implement a MY class
10 use File::Basename qw(dirname);
11 use File::Copy qw(copy);
12 use File::Find qw(find);
13 use File::Path qw(mkpath);
17 my($hash,$verbose,$nonono) = @_;
21 my(%pack, %write,$dir);
23 for (qw/read write/) {
28 foreach $blibdir (sort keys %hash) {
29 #Check if there are files, and if yes, look if the corresponding
30 #target directory is writable for us
31 opendir DIR, $blibdir or next;
32 while ($_ = readdir DIR) {
33 next if $_ eq "." || $_ eq ".." || $_ eq ".exists";
34 if (-w $hash{$blibdir} || mkpath($hash{$blibdir})) {
37 croak("You do not have permissions to install into $hash{$blibdir}");
42 if (-f $pack{"read"}) {
43 open P, $pack{"read"} or die "Couldn't read $pack{'read'}";
44 # Remember what you found
54 # This silly reference is just here to be able to call MY->catdir
55 # without a warning (Waiting for a proper path/directory module,
56 # Charles!) The catdir and catfile calls leave us with a lot of
57 # paths containing ././, but I don't want to use regexes on paths
58 # anymore to delete them :-)
62 MOD_INSTALL: foreach $source (sort keys %hash) {
63 #copy the tree to the target directory without altering
64 #timestamp and permission and remember for the .packlist
65 #file. The packlist file contains the absolute paths of the
66 #install locations. AFS users may call this a bug. We'll have
67 #to reconsider how to add the means to satisfy AFS users also.
68 chdir($source) or next;
70 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
71 $atime,$mtime,$ctime,$blksize,$blocks) = stat;
73 return if $_ eq ".exists";
74 my $targetdir = $MY->catdir($hash{$source},$File::Find::dir);
75 my $targetfile = $MY->catfile($targetdir,$_);
78 if ( -f $targetfile && -s _ == $size) {
79 # We have a good chance, we can skip this one
81 open F, $_ or croak("Couldn't open $_: $!");
82 open T, $targetfile or croak("Couldn't open $targetfile: $!");
83 my($fr, $tr, $fbuf,$tbuf,$size);
85 # print "Reading $_\n";
86 while ( $fr = read(F,$fbuf,$size)) {
88 $tr = read(T,$tbuf,$size) and
101 print "$_ differs\n" if $verbose>1;
106 mkpath($targetdir,0,0755) unless $nonono;
107 print "mkpath($targetdir,0,0755)\n" if $verbose>1;
108 unlink $targetfile if -f $targetfile;
109 copy($_,$targetfile) unless $nonono;
110 print "Installing $targetfile\n" if $verbose;
111 utime($atime,$mtime,$targetfile) unless $nonono>1;
112 print "utime($atime,$mtime,$targetfile)\n" if $verbose>1;
113 chmod $mode, $targetfile;
114 print "chmod($mode, $targetfile)\n" if $verbose>1;
116 print "Skipping $targetfile (unchanged)\n";
119 $write{$targetfile}++;
122 chdir($cwd) or croak("Couldn't chdir....");
125 if ($pack{'write'}) {
126 $dir = dirname($pack{'write'});
128 print "Writing $pack{'write'}\n";
129 open P, ">$pack{'write'}" or croak("Couldn't write $pack{'write'}: $!");
130 for (sort keys %write) {
138 my($fil,$verbose,$nonono) = @_;
139 die "no packlist file found: $fil" unless -f $fil;
141 open P, $fil or croak("uninstall: Could not read packlist file $fil: $!");
144 print "unlink $_\n" if $verbose;
145 unlink($_) || carp("Couldn't unlink $_") unless $nonono;
147 print "unlink $fil\n" if $verbose;
148 unlink($fil) || carp("Couldn't unlink $fil") unless $nonono;
157 ExtUtils::Install - install files from here to there
161 B<use ExtUtils::Install;>
163 B<install($hashref,$verbose,$nonono);>
165 B<uninstall($packlistfile,$verbose,$nonono);>
169 Both functions, install() and uninstall() are specific to the way
170 ExtUtils::MakeMaker handles the installation and deinstallation of
171 perl modules. They are not designed as general purpose tools.
173 install() takes three arguments. A reference to a hash, a verbose
174 switch and a don't-really-do-it switch. The hash ref contains a
175 mapping of directories: each key/value pair is a combination of
176 directories to be copied. Key is a directory to copy from, value is a
177 directory to copy to. The whole tree below the "from" directory will
178 be copied preserving timestamps and permissions.
180 There are two keys with a special meaning in the hash: "read" and
181 "write". After the copying is done, install will write the list of
182 target files to the file named by $hashref->{write}. If there is
183 another file named by $hashref->{read}, the contents of this file will
184 be merged into the written file. The read and the written file may be
185 identical, but on AFS it is quite likely, people are installing to a
186 different directory than the one where the files later appear.
188 uninstall() takes as first argument a file containing filenames to be
189 unlinked. The second argument is a verbose switch, the third is a
190 no-don't-really-do-it-now switch.