diff options
author | Wanlong Gao <gaowanlong@cn.fujitsu.com> | 2012-04-24 15:23:48 +0800 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-04-24 08:32:08 +0100 |
commit | 7fc7c3aa5b8088abc52b5cc39b682cdaedd1ba84 (patch) | |
tree | c66ea31e2c8670ddd82f14d326fec66cb505812d | |
parent | 95515c45762471c4f807ce442e1be85aac0da511 (diff) | |
download | libguestfs-7fc7c3aa5b8088abc52b5cc39b682cdaedd1ba84.tar.gz libguestfs-7fc7c3aa5b8088abc52b5cc39b682cdaedd1ba84.tar.xz libguestfs-7fc7c3aa5b8088abc52b5cc39b682cdaedd1ba84.zip |
sysprep: remove the cache of package manager
Remove the cache of package manager like yum and apt.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
RWMJ:
- Small code cleanup.
-rw-r--r-- | sysprep/Makefile.am | 2 | ||||
-rw-r--r-- | sysprep/sysprep_operation_package_manager_cache.ml | 45 |
2 files changed, 47 insertions, 0 deletions
diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am index e4b7f7b5..78b1fa1a 100644 --- a/sysprep/Makefile.am +++ b/sysprep/Makefile.am @@ -42,6 +42,7 @@ SOURCES = \ sysprep_operation_logfiles.ml \ sysprep_operation_mail_spool.ml \ sysprep_operation_net_hwaddr.ml \ + sysprep_operation_package_manager_cache.ml \ sysprep_operation_random_seed.ml \ sysprep_operation_rhn_systemid.ml \ sysprep_operation_script.ml \ @@ -69,6 +70,7 @@ OBJECTS = \ sysprep_operation_logfiles.cmx \ sysprep_operation_mail_spool.cmx \ sysprep_operation_net_hwaddr.cmx \ + sysprep_operation_package_manager_cache.ml \ sysprep_operation_random_seed.cmx \ sysprep_operation_rhn_systemid.cmx \ sysprep_operation_script.cmx \ diff --git a/sysprep/sysprep_operation_package_manager_cache.ml b/sysprep/sysprep_operation_package_manager_cache.ml new file mode 100644 index 00000000..80eefa31 --- /dev/null +++ b/sysprep/sysprep_operation_package_manager_cache.ml @@ -0,0 +1,45 @@ +(* virt-sysprep + * Copyright (C) 2012 FUJITSU LIMITED + * + * 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 + +module G = Guestfs + +let package_manager_cache_perform g root = + let packager = g#inspect_get_package_management root in + let cache_dirs = + match packager with + | "yum" -> + Some (g#glob_expand "/var/cache/yum/*") + | "apt" -> + Some (g#glob_expand "/var/cache/apt/archives/*") + | _ -> None in + match cache_dirs with + | Some dirs -> Array.iter g#rm_rf dirs; [] + | _ -> [] + +let package_manager_cache_op = { + name = "package-manager-cache"; + enabled_by_default = true; + heading = "Remove package manager cache"; + pod_description = None; + extra_args = []; + perform = package_manager_cache_perform; +} + +let () = register_operation package_manager_cache_op |