From dd21bec4009ad6a65be1634b513be50ee668a63a Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 24 Jun 2013 21:06:58 +0100 Subject: [PATCH] sysprep: New operation to remove RPM database files. See: https://lists.fedoraproject.org/pipermail/devel/2013-June/184389.html --- po/POTFILES-ml | 1 + sysprep/Makefile.am | 1 + sysprep/sysprep_operation_rpm_db.ml | 49 +++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 sysprep/sysprep_operation_rpm_db.ml diff --git a/po/POTFILES-ml b/po/POTFILES-ml index 566c6aee6..9e4a0435f 100644 --- a/po/POTFILES-ml +++ b/po/POTFILES-ml @@ -32,6 +32,7 @@ sysprep/sysprep_operation_pam_data.ml sysprep/sysprep_operation_puppet_data_log.ml sysprep/sysprep_operation_random_seed.ml sysprep/sysprep_operation_rhn_systemid.ml +sysprep/sysprep_operation_rpm_db.ml sysprep/sysprep_operation_samba_db_log.ml sysprep/sysprep_operation_script.ml sysprep/sysprep_operation_smolt_uuid.ml diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am index 81ffcc736..4572594b3 100644 --- a/sysprep/Makefile.am +++ b/sysprep/Makefile.am @@ -55,6 +55,7 @@ operations = \ puppet_data_log \ random_seed \ rhn_systemid \ + rpm_db \ samba_db_log \ script \ smolt_uuid \ diff --git a/sysprep/sysprep_operation_rpm_db.ml b/sysprep/sysprep_operation_rpm_db.ml new file mode 100644 index 000000000..b347c538f --- /dev/null +++ b/sysprep/sysprep_operation_rpm_db.ml @@ -0,0 +1,49 @@ +(* virt-sysprep + * Copyright (C) 2013 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + *) + +open Sysprep_operation +open Common_gettext.Gettext + +module StringSet = Set.Make (String) +module G = Guestfs + +let rpm_db_perform g root = + let pf = g#inspect_get_package_format root in + if pf = "rpm" then ( + let paths = g#glob_expand "/var/lib/rpm/__db.*" in + Array.iter ( + fun filename -> + try g#rm filename with G.Error _ -> () + ) paths; + [] + ) + else [] + +let rpm_db_op = { + name = "rpm-db"; + enabled_by_default = true; + heading = s_"Remove host-specific RPM database files"; + pod_description = Some (s_"\ +Remove host-specific RPM database files and locks. RPM will +recreate these files automatically if needed."); + extra_args = []; + perform_on_filesystems = Some rpm_db_perform; + perform_on_devices = None; +} + +let () = register_operation rpm_db_op