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