dpkg-distaddfile.pl 2.1 KB

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