Commit 690e72cd authored by Dietmar Maurer's avatar Dietmar Maurer

implement apt-get update

parent 92ebf7e0
...@@ -91,6 +91,35 @@ my $assemble_pkginfo = sub { ...@@ -91,6 +91,35 @@ my $assemble_pkginfo = sub {
return $data; return $data;
}; };
# we try to cache results
my $pve_pkgstatus_fn = "/var/lib/pve-manager/pkgupdates";
my $update_pve_pkgstatus = sub {
my $pkglist = [];
my $cache = &$get_apt_cache();
my $policy = $cache->policy;
my $pkgrecords = $cache->packages();
foreach my $pkgname (keys %$cache) {
my $p = $cache->{$pkgname};
next if $p->{SelectedState} ne 'Install';
my $current_ver = $p->{CurrentVer};
my $candidate_ver = $policy->candidate($p);
if ($current_ver->{VerStr} ne $candidate_ver->{VerStr}) {
my $info = $pkgrecords->lookup($pkgname);
my $res = &$assemble_pkginfo($pkgname, $info, $current_ver, $candidate_ver);
push @$pkglist, $res;
}
}
PVE::Tools::file_set_contents($pve_pkgstatus_fn, encode_json($pkglist));
return $pkglist;
};
__PACKAGE__->register_method({ __PACKAGE__->register_method({
name => 'list_updates', name => 'list_updates',
path => 'update', path => 'update',
...@@ -117,9 +146,6 @@ __PACKAGE__->register_method({ ...@@ -117,9 +146,6 @@ __PACKAGE__->register_method({
code => sub { code => sub {
my ($param) = @_; my ($param) = @_;
# we try to cache results
my $pve_pkgstatus_fn = "/var/lib/pve-manager/pkgupdates";
if (my $st1 = File::stat::stat($pve_pkgstatus_fn)) { if (my $st1 = File::stat::stat($pve_pkgstatus_fn)) {
my $st2 = File::stat::stat("/var/cache/apt/pkgcache.bin"); my $st2 = File::stat::stat("/var/cache/apt/pkgcache.bin");
my $st3 = File::stat::stat("/var/lib/dpkg/status"); my $st3 = File::stat::stat("/var/lib/dpkg/status");
...@@ -139,28 +165,53 @@ __PACKAGE__->register_method({ ...@@ -139,28 +165,53 @@ __PACKAGE__->register_method({
} }
} }
my $pkglist = []; my $pkglist = &$update_pve_pkgstatus();
my $cache = &$get_apt_cache(); return $pkglist;
my $policy = $cache->policy; }});
my $pkgrecords = $cache->packages();
foreach my $pkgname (keys %$cache) { __PACKAGE__->register_method({
my $p = $cache->{$pkgname}; name => 'update_database',
next if $p->{SelectedState} ne 'Install'; path => 'update',
my $current_ver = $p->{CurrentVer}; method => 'POST',
my $candidate_ver = $policy->candidate($p); description => "This is used to resynchronize the package index files from their sources (apt-get update).",
permissions => {
check => ['perm', '/nodes/{node}', [ 'Sys.Modify' ]],
},
protected => 1,
proxyto => 'node',
parameters => {
additionalProperties => 0,
properties => {
node => get_standard_option('pve-node'),
},
},
returns => {
type => 'string',
},
code => sub {
my ($param) = @_;
if ($current_ver->{VerStr} ne $candidate_ver->{VerStr}) { my $rpcenv = PVE::RPCEnvironment::get();
my $info = $pkgrecords->lookup($pkgname);
my $res = &$assemble_pkginfo($pkgname, $info, $current_ver, $candidate_ver);
push @$pkglist, $res;
}
}
PVE::Tools::file_set_contents($pve_pkgstatus_fn, encode_json($pkglist)); my $authuser = $rpcenv->get_user();
my $realcmd = sub {
my $upid = shift;
my $cmd = ['apt-get', 'update'];
print "starting apt-get update\n";
PVE::Tools::run_command($cmd);
&$update_pve_pkgstatus();
return;
};
return $rpcenv->fork_worker('apt', undef, $authuser, $realcmd);
return $pkglist;
}}); }});
1; 1;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment