Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pve-manager
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
pve-manager
Commits
92ebf7e0
Commit
92ebf7e0
authored
Jun 12, 2013
by
Dietmar Maurer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cache apt query in /var/lib/pve-manager/pkgupdates
parent
61a5235c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
APT.pm
PVE/API2/APT.pm
+26
-0
No files found.
PVE/API2/APT.pm
View file @
92ebf7e0
...
...
@@ -2,6 +2,7 @@ package PVE::API2::APT;
use
strict
;
use
warnings
;
use
File::
stat
();
use
PVE::
Tools
qw(extract_param)
;
use
PVE::
SafeSyslog
;
...
...
@@ -10,6 +11,7 @@ use PVE::Exception qw(raise_param_exc);
use
PVE::
RESTHandler
;
use
PVE::
RPCEnvironment
;
use
JSON
;
use
PVE::
JSONSchema
qw(get_standard_option)
;
use
AptPkg::
Cache
;
...
...
@@ -115,6 +117,28 @@ __PACKAGE__->register_method({
code
=>
sub
{
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
))
{
my
$st2
=
File::stat::
stat
("
/var/cache/apt/pkgcache.bin
");
my
$st3
=
File::stat::
stat
("
/var/lib/dpkg/status
");
if
(
$st2
->
mtime
<
$st1
->
mtime
&&
$st3
->
mtime
<
$st1
->
mtime
)
{
my
$data
;
eval
{
my
$jsonstr
=
PVE::Tools::
file_get_contents
(
$pve_pkgstatus_fn
,
5
*
1024
*
1024
);
$data
=
decode_json
(
$jsonstr
);
};
if
(
my
$err
=
$@
)
{
warn
"
error readin cached package status in
$pve_pkgstatus_fn
\n
";
# continue and overwrite cache with new content
}
else
{
return
$data
;
}
}
}
my
$pkglist
=
[]
;
my
$cache
=
&
$get_apt_cache
();
...
...
@@ -134,6 +158,8 @@ __PACKAGE__->register_method({
}
}
PVE::Tools::
file_set_contents
(
$pve_pkgstatus_fn
,
encode_json
(
$pkglist
));
return
$pkglist
;
}});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment