dpkg (1.18.25) stretch; urgency=medium
[dpkg] / scripts / dpkg-distaddfile.pl
CommitLineData
1479465f
GJ
1#!/usr/bin/perl
2#
3# dpkg-distaddfile
4#
5# Copyright © 1996 Ian Jackson
6# Copyright © 2006-2008,2010,2012-2014 Guillem Jover <guillem@debian.org>
7#
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.
12#
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.
17#
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/>.
20
21use strict;
22use warnings;
23
24use POSIX qw(:errno_h :fcntl_h);
25
26use Dpkg ();
27use Dpkg::Gettext;
28use Dpkg::ErrorHandling;
29use Dpkg::File;
30use Dpkg::Dist::Files;
31
32textdomain('dpkg-dev');
33
34my $fileslistfile = 'debian/files';
35
36
37sub version {
38 printf g_("Debian %s version %s.\n"), $Dpkg::PROGNAME, $Dpkg::PROGVERSION;
39
40 printf g_('
41This is free software; see the GNU General Public License version 2 or
42later for copying conditions. There is NO warranty.
43');
44}
45
46sub usage {
47 printf g_(
48'Usage: %s [<option>...] <filename> <section> <priority>
49
50Options:
51 -f<files-list-file> write files here instead of debian/files.
52 -?, --help show this help message.
53 --version show the version.
54'), $Dpkg::PROGNAME;
55}
56
57while (@ARGV && $ARGV[0] =~ m/^-/) {
58 $_=shift(@ARGV);
59 if (m/^-f/p) {
60 $fileslistfile = ${^POSTMATCH};
61 } elsif (m/^-(?:\?|-help)$/) {
62 usage();
63 exit(0);
64 } elsif (m/^--version$/) {
65 version();
66 exit(0);
67 } elsif (m/^--$/) {
68 last;
69 } else {
70 usageerr(g_("unknown option '%s'"), $_);
71 }
72}
73usageerr(g_('need exactly a filename, section and priority')) if @ARGV != 3;
74
75my ($filename, $section, $priority) = @ARGV;
76
77($filename =~ m/\s/ || $section =~ m/\s/ || $priority =~ m/\s/) &&
78 error(g_('filename, section and priority may contain no whitespace'));
79
80# Obtain a lock on debian/control to avoid simultaneous updates
81# of debian/files when parallel building is in use
82my $lockfh;
83my $lockfile = 'debian/control';
84sysopen($lockfh, $lockfile, O_WRONLY)
85 or syserr(g_('cannot write %s'), $lockfile);
86file_lock($lockfh, $lockfile);
87
88my $dist = Dpkg::Dist::Files->new();
89$dist->load($fileslistfile) if -e $fileslistfile;
90$dist->add_file($filename, $section, $priority);
91$dist->save("$fileslistfile.new");
92
93rename("$fileslistfile.new", $fileslistfile)
94 or syserr(g_('install new files list file'));
95
96# Release the lock
97close($lockfh) or syserr(g_('cannot close %s'), $lockfile);