dpkg-distaddfile.pl 2.0 KB

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