1 |
williamc |
1.1 |
#
|
2 |
|
|
# standard url interface for cvs
|
3 |
|
|
#
|
4 |
williamc |
1.12 |
# cvs urls
|
5 |
|
|
#
|
6 |
|
|
# cvs://server_name:/repository_location?passkey=xxx&auth=xxx&user=xxx
|
7 |
|
|
# &module=co_files
|
8 |
|
|
#
|
9 |
williamc |
1.9 |
# Interface
|
10 |
williamc |
1.1 |
#-------------
|
11 |
|
|
# new() :
|
12 |
williamc |
1.5 |
# get(url,$dirname) :
|
13 |
williamc |
1.1 |
|
14 |
williamc |
1.4 |
package URL::URL_cvs;
|
15 |
williamc |
1.1 |
require 5.001;
|
16 |
|
|
use Utilities::CVSmodule;
|
17 |
williamc |
1.12 |
use URL::URL_base;
|
18 |
williamc |
1.1 |
use Carp;
|
19 |
williamc |
1.12 |
@ISA = qw(URL::URL_base);
|
20 |
williamc |
1.1 |
|
21 |
|
|
sub init {
|
22 |
|
|
my $self=shift;
|
23 |
|
|
$self->{cvsco}="co";
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
sub setbase {
|
27 |
|
|
my $self=shift;
|
28 |
williamc |
1.7 |
my $base=shift;
|
29 |
williamc |
1.1 |
my $varhash=shift;
|
30 |
|
|
|
31 |
|
|
my $auth=$$varhash{'auth'};
|
32 |
|
|
|
33 |
|
|
# a new cvs object
|
34 |
|
|
$self->{cvsobject}=CVSmodule->new();
|
35 |
|
|
$self->{cvsobject}->set_base($base);
|
36 |
|
|
$self->{cvsobject}->set_auth($auth);
|
37 |
|
|
if ( exists $$varhash{'user'} ) {
|
38 |
|
|
$self->{cvsobject}->set_user($$varhash{'user'});
|
39 |
|
|
}
|
40 |
|
|
if ( exists $$varhash{'passkey'} ) {
|
41 |
|
|
$self->{cvsobject}->set_passkey($$varhash{'passkey'});
|
42 |
|
|
}
|
43 |
|
|
if ( exists $$varhash{'method'} ) {
|
44 |
|
|
$self->{cvsco}=$$varhash{'method'};
|
45 |
|
|
}
|
46 |
|
|
# Alternative dir name to co to
|
47 |
|
|
if ( exists $$varhash{'name'} ) {
|
48 |
|
|
$self->{dirname}=$$varhash{'name'};
|
49 |
|
|
}
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
sub get {
|
53 |
|
|
my $self=shift;
|
54 |
|
|
my $url=shift;
|
55 |
williamc |
1.6 |
my $location=shift;
|
56 |
williamc |
1.1 |
|
57 |
williamc |
1.6 |
use File::Basename;
|
58 |
williamc |
1.9 |
my ($dir,$dirname)=($location=~/(.*)\/(.*)/);
|
59 |
williamc |
1.7 |
#my $dir=dirname($location);
|
60 |
williamc |
1.8 |
use Utilities::AddDir;
|
61 |
williamc |
1.9 |
#AddDir::adddir($dir);
|
62 |
williamc |
1.6 |
|
63 |
|
|
my @cvscmd=($self->{cvsco});
|
64 |
williamc |
1.12 |
$self->setbase($url->servername().":/".$url->path(),$url->vars());
|
65 |
williamc |
1.7 |
my $version=$url->param('version');
|
66 |
williamc |
1.6 |
my $rv="";
|
67 |
williamc |
1.12 |
my $module;
|
68 |
|
|
($module=$url->param('module'))=~s/\/$//;
|
69 |
|
|
my $filename="";
|
70 |
|
|
if ( $module=~/\/.?/ ) {
|
71 |
|
|
($filename=$module)=~s/.*\///;
|
72 |
|
|
}
|
73 |
williamc |
1.1 |
|
74 |
williamc |
1.9 |
push @cvscmd, ("-d", "$dirname");
|
75 |
williamc |
1.7 |
if ( $version && ($version ne "") ) {
|
76 |
williamc |
1.6 |
push @cvscmd, ("-r", "$version");
|
77 |
williamc |
1.1 |
}
|
78 |
|
|
#
|
79 |
|
|
# Check to see we have a server and if so attempt the checkout
|
80 |
|
|
#
|
81 |
|
|
if ( ! defined $self->{cvsobject} ) {
|
82 |
williamc |
1.12 |
$self->error("undefined cvs server for $module");
|
83 |
williamc |
1.1 |
}
|
84 |
|
|
else {
|
85 |
williamc |
1.12 |
if ( ! defined $module ) {
|
86 |
|
|
$self->error("undefined module to checkout");
|
87 |
|
|
}
|
88 |
|
|
else {
|
89 |
williamc |
1.5 |
use Cwd;
|
90 |
|
|
my $thisdir=cwd();
|
91 |
williamc |
1.9 |
chdir $dir or die "unable to enter directory $dir\n";
|
92 |
williamc |
1.12 |
# print "Entering $dir to @cvscmd ".$module."\n";
|
93 |
|
|
$self->{cvsobject}->invokecvs(@cvscmd, $module);
|
94 |
williamc |
1.5 |
chdir $thisdir;
|
95 |
williamc |
1.9 |
if ( -e $location."/".$filename ) {
|
96 |
williamc |
1.12 |
$rv=$location."/".$filename;
|
97 |
|
|
$rv=~s/\/$//;
|
98 |
|
|
}
|
99 |
williamc |
1.9 |
else {
|
100 |
williamc |
1.12 |
$self->error("Download failed for ".$url->url());
|
101 |
williamc |
1.9 |
#print $location."/".$filename." does not exist\n";
|
102 |
|
|
}
|
103 |
williamc |
1.12 |
}
|
104 |
williamc |
1.9 |
}
|
105 |
williamc |
1.3 |
return $rv;
|
106 |
williamc |
1.12 |
}
|
107 |
|
|
|
108 |
|
|
sub error {
|
109 |
|
|
my $self=shift;
|
110 |
|
|
my $string=shift;
|
111 |
|
|
|
112 |
|
|
print "cvs handler error: ".$string."\n";
|
113 |
williamc |
1.1 |
}
|