dpkg-distaddfile.pl 2.7 KB

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