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