summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <thierry.vignaud@gmail.com>2021-06-05 09:08:24 +0200
committerThierry Vignaud <thierry.vignaud@gmail.com>2021-06-05 12:37:18 +0200
commitc338043e44c14fc023e6386cf62c0acf97da51be (patch)
treec613a91cfb3fbb391b21b8164c01eafbd8592f02
parentf06d11cd8e450d6542c6b7cc371dead6f8294e4b (diff)
downloadurpmi-c338043e44c14fc023e6386cf62c0acf97da51be.tar
urpmi-c338043e44c14fc023e6386cf62c0acf97da51be.tar.gz
urpmi-c338043e44c14fc023e6386cf62c0acf97da51be.tar.bz2
urpmi-c338043e44c14fc023e6386cf62c0acf97da51be.tar.xz
urpmi-c338043e44c14fc023e6386cf62c0acf97da51be.zip
Convert from bdb backend to sqlite
Rationale: - sqlite backend is supported since rpm-4.16 - bdb backend is deprecated in 4.16 & removed in 4.17 (really 4.16.90)
-rw-r--r--Changes2
-rw-r--r--urpm/main_loop.pm2
-rw-r--r--urpm/select.pm21
-rw-r--r--urpm/sys.pm33
4 files changed, 58 insertions, 0 deletions
diff --git a/Changes b/Changes
index 2d2774f8..5b0cfe04 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,5 @@
+- Convert from bdb backend to sqlite when using rpm >= 4.16
+
Version 8.125 - 17 February 2021
- translation updates
diff --git a/urpm/main_loop.pm b/urpm/main_loop.pm
index cb8fc1f2..6e4820ab 100644
--- a/urpm/main_loop.pm
+++ b/urpm/main_loop.pm
@@ -497,6 +497,8 @@ sub run {
my (@errors, @formatted_errors);
$exit_code = 0;
+ urpm::select::migrate_forward_rpmdb_db_if_needed($urpm, $state);
+
my $migrate_back_rpmdb_db_version =
$urpm->{root} && urpm::select::should_we_migrate_back_rpmdb_db_version($urpm, $state);
diff --git a/urpm/select.pm b/urpm/select.pm
index a015f7a5..dbde19a3 100644
--- a/urpm/select.pm
+++ b/urpm/select.pm
@@ -756,6 +756,27 @@ sub should_we_migrate_back_rpmdb_db_version {
0;
}
+sub migrate_forward_rpmdb_db_if_needed {
+ my ($urpm, $state) = @_;
+
+ my ($pkg) = selected_packages_providing($urpm, $state, 'rpm') or return;
+ my $rooted_rpm_version = version->new("v" . $pkg->version); # perl_checker: $self = revision
+ my $rpm_version = _rpm_version(); # perl_checker: $self = revision
+
+ if ($rpm_version ge v4.16.0) {
+ if ($rooted_rpm_version && $rooted_rpm_version ge v4.16) {
+ $urpm->{debug} and $urpm->{debug}("chrooted db version used by librpm is at least as good as non-rooted one");
+ if (-f "$urpm->{root}/var/lib/rpm/Packages") {
+ $urpm->{debug} and $urpm->{debug}("Migrating chrooted db");
+ $urpm->{need_migrate_rpmdb_now} = '4.16';
+ urpm::sys::migrate_forward_rpmdb_db_version($urpm, $urpm->{root});
+ return 1;
+ }
+ }
+ }
+ 0;
+}
+
1;
=back
diff --git a/urpm/sys.pm b/urpm/sys.pm
index b7cb1220..d8da722a 100644
--- a/urpm/sys.pm
+++ b/urpm/sys.pm
@@ -288,6 +288,39 @@ sub migrate_back_rpmdb_db_version {
clean_rpmdb_shared_regions($root);
}
+=item migrate_rpmdb_to_sqlite($urpm, $root)
+
+Migrate rpmdb to the new sqlite backend.
+
+=cut
+
+sub migrate_rpmdb_to_sqlite {
+ my ($urpm, $root) = @_;
+ $urpm->{info}("migrating db from bdb to sqlite (rpm >= 4.16)");
+ # Whatever is the default backend:
+ URPM::add_macro('_db_backend sqlite');
+ if (system('chroot', $root, 'rpm', '--rebuilddb') == 0) {
+ $urpm->{log}("rpm db converted to sqlite successfully");
+ } else {
+ $urpm->{error}("rpm db conversion failed. You will not be able to run rpm >= 4.17");
+ }
+}
+
+=item migrate_forward_rpmdb_db_version($urpm, $root)
+
+Check if we need to migrate rpmdb to a new backend prior to use it
+and do it if needed.
+
+=cut
+
+sub migrate_forward_rpmdb_db_version {
+ my ($urpm, $root) = @_;
+
+ if ($urpm->{need_migrate_rpmdb_now} eq '4.16') {
+ migrate_rpmdb_to_sqlite($urpm, $root);
+ }
+}
+
=item apply_delta_rpm($deltarpm, $o_dir, $o_pkg)