dpkg-distaddfile.pl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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;
  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();
  35. exit(0);
  36. } elsif (m/^--version$/) {
  37. version();
  38. 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. if (open(X,"< $fileslistfile")) {
  52. while (<X>) {
  53. s/\n$//;
  54. next if m/^(\S+) / && $1 eq $file;
  55. print(Y "$_\n") || syserr(_g("copy old entry to new files list file"));
  56. }
  57. } elsif ($! != ENOENT) {
  58. syserr(_g("read old files list file"));
  59. }
  60. print(Y "$file $section $priority\n")
  61. || syserr(_g("write new entry to new files list file"));
  62. close(Y) || syserr(_g("close new files list file"));
  63. rename("$fileslistfile.new", $fileslistfile) ||
  64. syserr(_g("install new files list file"));