dpkg-distaddfile.pl 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. our $progname;
  5. our $version = '1.3.0'; # This line modified by Makefile
  6. our $dpkglibdir = "."; # This line modified by Makefile
  7. use POSIX;
  8. use POSIX qw(:errno_h :signal_h);
  9. push(@INC,$dpkglibdir);
  10. require 'controllib.pl';
  11. require 'dpkg-gettext.pl';
  12. textdomain("dpkg-dev");
  13. my $fileslistfile = 'debian/files';
  14. sub version {
  15. printf _g("Debian %s version %s.\n"), $progname, $version;
  16. printf _g("
  17. Copyright (C) 1996 Ian Jackson.");
  18. printf _g("
  19. This is free software; see the GNU General Public Licence version 2 or
  20. later for copying conditions. There is NO warranty.
  21. ");
  22. }
  23. sub usage {
  24. printf _g(
  25. "Usage: %s [<option>...] <filename> <section> <priority>
  26. Options:
  27. -f<fileslistfile> write files here instead of debian/files.
  28. -h, --help show this help message.
  29. --version show the version.
  30. "), $progname;
  31. }
  32. while (@ARGV && $ARGV[0] =~ m/^-/) {
  33. $_=shift(@ARGV);
  34. if (m/^-f/) {
  35. $fileslistfile= $';
  36. } elsif (m/^-(h|-help)$/) {
  37. &usage; exit(0);
  38. } elsif (m/^--version$/) {
  39. &version; exit(0);
  40. } elsif (m/^--$/) {
  41. last;
  42. } else {
  43. &usageerr(sprintf(_g("unknown option \`%s'"), $_));
  44. }
  45. }
  46. @ARGV==3 || &usageerr(_g("need exactly a filename, section and priority"));
  47. my ($file, $section, $priority) = @ARGV;
  48. ($file =~ m/\s/ || $section =~ m/\s/ || $priority =~ m/\s/) &&
  49. &error(_g("filename, section and priority may contain no whitespace"));
  50. $fileslistfile="./$fileslistfile" if $fileslistfile =~ m/^\s/;
  51. open(Y,"> $fileslistfile.new") || &syserr(_g("open new files list file"));
  52. chown(getfowner(), "$fileslistfile.new")
  53. || &syserr(_g("chown new files list file"));
  54. if (open(X,"< $fileslistfile")) {
  55. while (<X>) {
  56. s/\n$//;
  57. next if m/^(\S+) / && $1 eq $file;
  58. print(Y "$_\n") || &syserr(_g("copy old entry to new files list file"));
  59. }
  60. } elsif ($! != ENOENT) {
  61. &syserr(_g("read old files list file"));
  62. }
  63. print(Y "$file $section $priority\n")
  64. || &syserr(_g("write new entry to new files list file"));
  65. close(Y) || &syserr(_g("close new files list file"));
  66. rename("$fileslistfile.new",$fileslistfile) || &syserr(gettetx("install new files list file"));