dpkg-distaddfile.pl 1.9 KB

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