dpkg-distaddfile.pl 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/perl
  2. $dpkglibdir= ".";
  3. $version= '1.3.0'; # This line modified by Makefile
  4. use POSIX;
  5. use POSIX qw(:errno_h :signal_h);
  6. $fileslistfile= 'debian/files';
  7. push(@INC,$dpkglibdir);
  8. require 'controllib.pl';
  9. require 'dpkg-gettext.pl';
  10. textdomain("dpkg-dev");
  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(sprintf(_g("unknown option \`%s'"), $_));
  41. }
  42. }
  43. @ARGV==3 || &usageerr(_g("need exactly a filename, section and priority"));
  44. ($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. chown(getfowner(), "$fileslistfile.new")
  50. || &syserr(_g("chown 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) || &syserr(gettetx("install new files list file"));