]> git.donarmstrong.com Git - debhelper.git/blob - dh_movefiles
r399: * dh_movefiles: added error message on file not found
[debhelper.git] / dh_movefiles
1 #!/usr/bin/perl -w
2 #
3 # Move files out of debian/tmp, into subpackages.
4
5 use Debian::Debhelper::Dh_Lib;
6 init();
7
8 $ret=0;
9
10 foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
11         $TMP=tmpdir($PACKAGE);
12         $files=pkgfile($PACKAGE,"files");
13
14         if ($dh{SOURCEDIR}) {
15                 if ($dh{SOURCEDIR}=~m:^/:) {
16                         error("The sourcedir must be a relative filename, not starting with `/'.");
17                 }
18                 $sourcedir=$dh{SOURCEDIR};
19         }
20         else {
21                 $sourcedir="debian/tmp";
22         }
23
24         if (! -d $sourcedir) {
25                 error("$sourcedir does not exist.");
26         }
27
28         @tomove=();
29
30         # debian/files has a different purpose, so ignore it.
31         if ( $files && $files ne "debian/files" ) {
32                 @tomove=filearray($files, $sourcedir);
33         }
34         
35         if (($PACKAGE eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) {
36                 push @tomove, @ARGV;
37         }
38
39         if (@tomove && $TMP eq $sourcedir) {
40                 error("I was asked to move files from $sourcedir to $sourcedir. Perhaps you should set DH_COMAPT=2?");
41         }
42
43         # Now we need to expand wildcards in @tomove.
44         # This is only necessary in pre-v3 land -- as of v3, the
45         # expension is automatically done by filearray().
46         if (@tomove && ! Debian::Debhelper::Dh_Lib::compat(3)) {
47                 @filelist=();
48                 foreach (@tomove) {
49                         push @filelist, glob("$sourcedir/$_");
50                 }
51                 @tomove=@filelist;
52         }
53
54         if (@tomove) {
55                 if (! -d $TMP) {
56                         doit("install","-d",$TMP);
57                 }
58
59                 doit("rm","-f","debian/movelist");
60                 foreach (@tomove) {
61                         $file=$_;
62                         if (! -e $file && ! -l $file) {
63                                 $ret=1;
64                                 warning("$file not found");
65                         }
66                         $file=~s:^\Q$sourcedir\E/+::;
67                         complex_doit("(cd $sourcedir >/dev/null ; find $file ! -type d -print || true) >> debian/movelist");
68                 }
69                 complex_doit("(cd $sourcedir >/dev/null ; tar --create --remove-files --files-from=../movelist --file -) | (cd $TMP >/dev/null ;tar xpf -)");
70                 doit("rm","-f","debian/movelist");
71         }
72 }
73
74 # If $ret is set, we wern't actually able to find some 
75 # files that were specified to be moved, and we should
76 # exit with the code in $ret. This program puts off 
77 # exiting with an error until all files have been tried
78 # to be moved, because this makes it easier for some 
79 # packages that arn't always sure exactly which files need
80 # to be moved.
81 exit $ret;