summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2011-07-19 17:30:06 +0000
committerMarc Espie <espie@cvs.openbsd.org>2011-07-19 17:30:06 +0000
commit5a7f9213701f3848ea0439ba3960564ac99aa3a8 (patch)
treeadff1a03c03a15bb03921c3f88cf72fe0e1fe4a8 /usr.sbin/pkg_add
parent875839cf13a48a9d1981bc56e48e6d73b45826bf (diff)
use common code for ssh/http 1.1
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageRepository/SCP.pm119
1 files changed, 4 insertions, 115 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository/SCP.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository/SCP.pm
index 9f2296dfb80..e0aa597a2dd 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageRepository/SCP.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository/SCP.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: SCP.pm,v 1.26 2011/03/23 15:29:31 espie Exp $
+# $OpenBSD: SCP.pm,v 1.27 2011/07/19 17:30:05 espie Exp $
#
# Copyright (c) 2003-2006 Marc Espie <espie@openbsd.org>
#
@@ -18,8 +18,10 @@
use strict;
use warnings;
+use OpenBSD::PackageRepository::Persistant;
+
package OpenBSD::PackageRepository::SCP;
-our @ISA=qw(OpenBSD::PackageRepository::Distant);
+our @ISA=qw(OpenBSD::PackageRepository::Persistant);
use IPC::Open2;
use IO::Handle;
@@ -30,8 +32,6 @@ sub urlscheme
return 'scp';
}
-our %distant = ();
-
# Any SCP repository uses one single connection, reliant on a perl at end.
# The connection starts by xfering and firing up the `distant' script.
sub initiate
@@ -57,117 +57,6 @@ sub initiate
seek(DATA, 0, 0);
}
-
-sub may_exist
-{
- my ($self, $name) = @_;
- my $l = $self->list;
- return grep {$_ eq $name } @$l;
-}
-
-sub grab_object
-{
- my ($self, $object) = @_;
-
- my $cmdfh = $self->{cmdfh};
- my $getfh = $self->{getfh};
-
- print $cmdfh "ABORT\n";
- my $_;
- while (<$getfh>) {
- last if m/^ABORTED/o;
- }
- print $cmdfh "GET ", $self->{path}.$object->{name}.".tgz", "\n";
- close($cmdfh);
- $_ = <$getfh>;
- chomp;
- if (m/^ERROR:/o) {
- $self->{state}->fatal("transfer error: #1", $_);
- }
- if (m/^TRANSFER:\s+(\d+)/o) {
- my $buffsize = 10 * 1024;
- my $buffer;
- my $size = $1;
- my $remaining = $size;
- my $n;
-
- do {
- $n = read($getfh, $buffer,
- $remaining < $buffsize ? $remaining :$buffsize);
- if (!defined $n) {
- $self->{state}->fatal("Error reading: #1", $!);
- }
- $remaining -= $n;
- if ($n > 0) {
- syswrite STDOUT, $buffer;
- }
- } while ($n != 0 && $remaining != 0);
- exit(0);
- }
-}
-
-sub maxcount
-{
- return 1;
-}
-
-sub opened
-{
- my $self = $_[0];
- my $k = $self->{host};
- if (!defined $distant{$k}) {
- $distant{$k} = [];
- }
- return $distant{$k};
-}
-
-sub list
-{
- my ($self) = @_;
- if (!defined $self->{list}) {
- if (!defined $self->{controller}) {
- $self->initiate;
- }
- my $cmdfh = $self->{cmdfh};
- my $getfh = $self->{getfh};
- my $path = $self->{path};
- my $l = [];
- print $cmdfh "LIST $path\n";
- my $_;
- $_ = <$getfh>;
- if (!defined $_) {
- $self->{state}->fatal("Could not initiate SSH session");
- }
- chomp;
- if (m/^ERROR:/o) {
- $self->{state}->fatal("#1", $_);
- }
- if (!m/^SUCCESS:/o) {
- $self->{state}->fatal("Synchronization error");
- }
- while (<$getfh>) {
- chomp;
- last if $_ eq '';
- push(@$l, $_);
- }
- $self->{list} = $l;
- }
- return $self->{list};
-}
-
-sub cleanup
-{
- my $self = shift;
- if (defined $self->{controller}) {
- my $cmdfh = $self->{cmdfh};
- my $getfh = $self->{getfh};
- print $cmdfh "ABORT\nBYE\nBYE\n";
- CORE::close($cmdfh);
- CORE::close($getfh);
- waitpid($self->{controller}, 0);
- }
-}
-
1;
__DATA__
# Distant connection script.