dpkg-distaddfile.pl 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/usr/bin/perl
  2. #
  3. # dpkg-distaddfile
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. use strict;
  18. use warnings;
  19. use POSIX;
  20. use POSIX qw(:errno_h :signal_h);
  21. use Dpkg;
  22. use Dpkg::Gettext;
  23. use Dpkg::ErrorHandling;
  24. textdomain("dpkg-dev");
  25. my $fileslistfile = 'debian/files';
  26. sub version {
  27. printf _g("Debian %s version %s.\n"), $progname, $version;
  28. printf _g("
  29. Copyright (C) 1996 Ian Jackson.");
  30. printf _g("
  31. This is free software; see the GNU General Public Licence version 2 or
  32. later for copying conditions. There is NO warranty.
  33. ");
  34. }
  35. sub usage {
  36. printf _g(
  37. "Usage: %s [<option>...] <filename> <section> <priority>
  38. Options:
  39. -f<fileslistfile> write files here instead of debian/files.
  40. -h, --help show this help message.
  41. --version show the version.
  42. "), $progname;
  43. }
  44. while (@ARGV && $ARGV[0] =~ m/^-/) {
  45. $_=shift(@ARGV);
  46. if (m/^-f/) {
  47. $fileslistfile= $';
  48. } elsif (m/^-(h|-help)$/) {
  49. usage();
  50. exit(0);
  51. } elsif (m/^--version$/) {
  52. version();
  53. exit(0);
  54. } elsif (m/^--$/) {
  55. last;
  56. } else {
  57. usageerr(_g("unknown option \`%s'"), $_);
  58. }
  59. }
  60. @ARGV == 3 || usageerr(_g("need exactly a filename, section and priority"));
  61. my ($file, $section, $priority) = @ARGV;
  62. ($file =~ m/\s/ || $section =~ m/\s/ || $priority =~ m/\s/) &&
  63. error(_g("filename, section and priority may contain no whitespace"));
  64. $fileslistfile="./$fileslistfile" if $fileslistfile =~ m/^\s/;
  65. open(Y, "> $fileslistfile.new") || syserr(_g("open new files list file"));
  66. if (open(X,"< $fileslistfile")) {
  67. while (<X>) {
  68. s/\n$//;
  69. next if m/^(\S+) / && $1 eq $file;
  70. print(Y "$_\n") || syserr(_g("copy old entry to new files list file"));
  71. }
  72. } elsif ($! != ENOENT) {
  73. syserr(_g("read old files list file"));
  74. }
  75. print(Y "$file $section $priority\n")
  76. || syserr(_g("write new entry to new files list file"));
  77. close(Y) || syserr(_g("close new files list file"));
  78. rename("$fileslistfile.new", $fileslistfile) ||
  79. syserr(_g("install new files list file"));