5 # Copyright © 1996 Ian Jackson
6 # Copyright © 2006-2008,2010,2012-2014 Guillem Jover <guillem@debian.org>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <https://www.gnu.org/licenses/>.
24 use POSIX
qw(:errno_h :fcntl_h);
28 use Dpkg
::ErrorHandling
;
30 use Dpkg
::Dist
::Files
;
32 textdomain
('dpkg-dev');
34 my $fileslistfile = 'debian/files';
38 printf g_
("Debian %s version %s.\n"), $Dpkg::PROGNAME
, $Dpkg::PROGVERSION
;
41 This is free software; see the GNU General Public License version 2 or
42 later for copying conditions. There is NO warranty.
48 'Usage: %s [<option>...] <filename> <section> <priority>
51 -f<files-list-file> write files here instead of debian/files.
52 -?, --help show this help message.
53 --version show the version.
57 while (@ARGV && $ARGV[0] =~ m/^-/) {
60 $fileslistfile = ${^POSTMATCH
};
61 } elsif (m/^-(?:\?|-help)$/) {
64 } elsif (m/^--version$/) {
70 usageerr
(g_
("unknown option '%s'"), $_);
73 usageerr
(g_
('need exactly a filename, section and priority')) if @ARGV != 3;
75 my ($filename, $section, $priority) = @ARGV;
77 ($filename =~ m/\s/ || $section =~ m/\s/ || $priority =~ m/\s/) &&
78 error
(g_
('filename, section and priority may contain no whitespace'));
80 # Obtain a lock on debian/control to avoid simultaneous updates
81 # of debian/files when parallel building is in use
83 my $lockfile = 'debian/control';
84 sysopen($lockfh, $lockfile, O_WRONLY
)
85 or syserr
(g_
('cannot write %s'), $lockfile);
86 file_lock
($lockfh, $lockfile);
88 my $dist = Dpkg
::Dist
::Files
->new();
89 $dist->load($fileslistfile) if -e
$fileslistfile;
90 $dist->add_file($filename, $section, $priority);
91 $dist->save("$fileslistfile.new");
93 rename("$fileslistfile.new", $fileslistfile)
94 or syserr
(g_
('install new files list file'));
97 close($lockfh) or syserr
(g_
('cannot close %s'), $lockfile);