FileSource.pm 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # $OpenBSD: FileSource.pm,v 1.3 2014/07/09 11:26:11 espie Exp $
  2. # Copyright (c) 2004-2010 Marc Espie <espie@openbsd.org>
  3. #
  4. # Permission to use, copy, modify, and distribute this software for any
  5. # purpose with or without fee is hereby granted, provided that the above
  6. # copyright notice and this permission notice appear in all copies.
  7. #
  8. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. use strict;
  16. use warnings;
  17. # part of check-lib-depends
  18. # FileSource: where we get the files to analyze
  19. package OpenBSD::FileSource;
  20. sub directory
  21. {
  22. my $self = shift;
  23. return $self->{location};
  24. }
  25. # file system
  26. package OpenBSD::FsFileSource;
  27. our @ISA = qw(OpenBSD::FileSource);
  28. sub new
  29. {
  30. my ($class, $location) = @_;
  31. bless {location => $location }, $class
  32. }
  33. sub retrieve
  34. {
  35. my ($self, $state, $item) = @_;
  36. return $item->fullname;
  37. }
  38. sub skip
  39. {
  40. }
  41. sub clean
  42. {
  43. }
  44. # package archive
  45. package OpenBSD::PkgFileSource;
  46. our @ISA = qw(OpenBSD::FileSource);
  47. sub new
  48. {
  49. my ($class, $handle, $location) = @_;
  50. bless {handle => $handle, location => $location }, $class;
  51. }
  52. sub prepare_to_extract
  53. {
  54. my ($self, $item) = @_;
  55. require OpenBSD::ArcCheck;
  56. my $o = $self->{handle}->next;
  57. $o->{cwd} = $item->cwd;
  58. if (!$o->check_name($item)) {
  59. die "Error checking name for $o->{name} vs. $item->{name}\n";
  60. }
  61. $o->{name} = $item->fullname;
  62. $o->{destdir} = $self->{location};
  63. return $o;
  64. }
  65. sub next
  66. {
  67. my $self = shift;
  68. my $o = $self->{handle}->next;
  69. if (defined $o) {
  70. $o->{destdir} = $self->{location};
  71. }
  72. return $o;
  73. }
  74. sub extracted_name
  75. {
  76. my ($self, $item) = @_;
  77. return $self->{location}.$item->fullname;
  78. }
  79. sub retrieve
  80. {
  81. my ($self, $state, $item) = @_;
  82. my $o = $self->prepare_to_extract($item);
  83. $o->create;
  84. return $item->fullname;
  85. }
  86. sub skip
  87. {
  88. my ($self, $item) = @_;
  89. my $o = $self->prepare_to_extract($item);
  90. $self->{handle}->skip;
  91. }
  92. sub clean
  93. {
  94. my ($self, $item) = @_;
  95. unlink($self->extracted_name($item));
  96. }
  97. 1;