Commit | Line | Data |
---|---|---|
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 | ||
21 | use strict; | |
22 | use warnings; | |
23 | ||
24 | use POSIX qw(:errno_h :fcntl_h); | |
25 | ||
26 | use Dpkg (); | |
27 | use Dpkg::Gettext; | |
28 | use Dpkg::ErrorHandling; | |
29 | use Dpkg::File; | |
30 | use Dpkg::Dist::Files; | |
31 | ||
32 | textdomain('dpkg-dev'); | |
33 | ||
34 | my $fileslistfile = 'debian/files'; | |
35 | ||
36 | ||
37 | sub version { | |
38 | printf g_("Debian %s version %s.\n"), $Dpkg::PROGNAME, $Dpkg::PROGVERSION; | |
39 | ||
40 | printf g_(' | |
41 | This is free software; see the GNU General Public License version 2 or | |
42 | later for copying conditions. There is NO warranty. | |
43 | '); | |
44 | } | |
45 | ||
46 | sub usage { | |
47 | printf g_( | |
48 | 'Usage: %s [<option>...] <filename> <section> <priority> | |
49 | ||
50 | Options: | |
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 | ||
57 | while (@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 | } | |
73 | usageerr(g_('need exactly a filename, section and priority')) if @ARGV != 3; | |
74 | ||
75 | my ($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 | |
82 | my $lockfh; | |
83 | my $lockfile = 'debian/control'; | |
84 | sysopen($lockfh, $lockfile, O_WRONLY) | |
85 | or syserr(g_('cannot write %s'), $lockfile); | |
86 | file_lock($lockfh, $lockfile); | |
87 | ||
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"); | |
92 | ||
93 | rename("$fileslistfile.new", $fileslistfile) | |
94 | or syserr(g_('install new files list file')); | |
95 | ||
96 | # Release the lock | |
97 | close($lockfh) or syserr(g_('cannot close %s'), $lockfile); |