]> git.donarmstrong.com Git - debhelper.git/blob - dh_movefiles
r378: * dh_movefiles: fixed a regexp quoting problem with --sourcedir.
[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);
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         if (@tomove) {
44                 if (! -d $TMP) {
45                         doit("install","-d",$TMP);
46                 }
47                 # Now we need to expand wildcards in @tomove.
48                 @filelist=();
49                 foreach (@tomove) {
50                         push @filelist, glob("$sourcedir/$_");
51                 }
52
53                 # If the globs expended to nothing, we are done.
54                 next unless @filelist;
55
56                 # Order the files. First all real files, then symlinks. 
57                 # Putting symlinks last is a nice thing to do for library 
58                 # packages and doesn't affect much of anything else.
59                 doit("rm","-f","debian/movelist");
60                 foreach (@filelist) {
61                         $file=$_;
62                         $ret=1 if (! -e $file && ! -l $file);
63                         $file=~s:^\Q$sourcedir\E/+::;
64                         complex_doit("(cd $sourcedir >/dev/null ; find $file ! -type d -and ! -type l -print || true) >> debian/movelist");
65                 }
66                 foreach (@filelist) {
67                         $file=$_;
68                         $ret=1 if (! -e $file && ! -l $file);
69                         $file=~s:^\Q$sourcedir\E/+::;
70                         complex_doit("(cd $sourcedir >/dev/null ; find $file ! -type d -and -type l -print || true) >> debian/movelist");
71                 }
72                 complex_doit("(cd $sourcedir >/dev/null ; tar --create --remove-files --files-from=../movelist --file -) | (cd $TMP >/dev/null ;tar xpf -)");
73                 doit("rm","-f","debian/movelist");
74         }
75 }
76
77 # If $ret is set, we wern't actually able to find some 
78 # files that were specified to be moved, and we should
79 # exit with the code in $ret. This program puts off 
80 # exiting with an error until all files have been tried
81 # to be moved, because this makes it easier for some 
82 # packages that arn't always sure exactly which files need
83 # to be moved.
84 exit $ret;