dpkg-distaddfile.pl 1.7 KB

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