From 5dd0d5da40b7f2c2172f9d63d0da4d20b0fe9ec1 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 9 Jul 2013 20:05:31 -0400 Subject: [PATCH] libostree: Move prune into OstreeRepo namespace More library work. --- Makefile-libostree.am | 1 + Makefile-ostree.am | 2 - .../ostree-repo-prune.c} | 26 +++++------ src/libostree/ostree-repo.h | 14 ++++++ src/ostree/ostree-prune.h | 43 ------------------- src/ostree/ot-admin-cleanup.c | 9 ++-- src/ostree/ot-admin-functions.c | 3 +- src/ostree/ot-builtin-prune.c | 16 +++---- 8 files changed, 41 insertions(+), 73 deletions(-) rename src/{ostree/ostree-prune.c => libostree/ostree-repo-prune.c} (88%) delete mode 100644 src/ostree/ostree-prune.h diff --git a/Makefile-libostree.am b/Makefile-libostree.am index 3de3469b..3e5bce64 100644 --- a/Makefile-libostree.am +++ b/Makefile-libostree.am @@ -33,6 +33,7 @@ libostree_la_SOURCES = src/libostree/ostree.h \ src/libostree/ostree-repo.c \ src/libostree/ostree-repo-checkout.c \ src/libostree/ostree-repo-libarchive.c \ + src/libostree/ostree-repo-prune.c \ src/libostree/ostree-repo-refs.c \ src/libostree/ostree-repo-traverse.c \ src/libostree/ostree-repo.h \ diff --git a/Makefile-ostree.am b/Makefile-ostree.am index 3962104a..8083bf2d 100644 --- a/Makefile-ostree.am +++ b/Makefile-ostree.am @@ -22,8 +22,6 @@ bin_PROGRAMS += ostree ostree_SOURCES = src/ostree/main.c \ src/ostree/ostree-curl-fetcher.h \ src/ostree/ostree-curl-fetcher.c \ - src/ostree/ostree-prune.h \ - src/ostree/ostree-prune.c \ src/ostree/ot-builtin-admin.c \ src/ostree/ot-builtins.h \ src/ostree/ot-builtin-cat.c \ diff --git a/src/ostree/ostree-prune.c b/src/libostree/ostree-repo-prune.c similarity index 88% rename from src/ostree/ostree-prune.c rename to src/libostree/ostree-repo-prune.c index 741e6b88..0f173d50 100644 --- a/src/ostree/ostree-prune.c +++ b/src/libostree/ostree-repo-prune.c @@ -1,6 +1,6 @@ /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- * - * Copyright (C) 2011 Colin Walters + * Copyright (C) 2011,2013 Colin Walters * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -22,7 +22,7 @@ #include "config.h" -#include "ostree-prune.h" +#include "ostree-repo.h" typedef struct { OstreeRepo *repo; @@ -36,7 +36,7 @@ typedef struct { static gboolean maybe_prune_loose_object (OtPruneData *data, - OstreePruneFlags flags, + OstreeRepoPruneFlags flags, const char *checksum, OstreeObjectType objtype, GCancellable *cancellable, @@ -52,7 +52,7 @@ maybe_prune_loose_object (OtPruneData *data, if (!g_hash_table_lookup_extended (data->reachable, key, NULL, NULL)) { - if (!(flags & OSTREE_PRUNE_FLAGS_NO_PRUNE)) + if (!(flags & OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE)) { gs_unref_object GFileInfo *info = NULL; @@ -85,14 +85,14 @@ maybe_prune_loose_object (OtPruneData *data, } gboolean -ostree_prune (OstreeRepo *repo, - OstreePruneFlags flags, - gint depth, - gint *out_objects_total, - gint *out_objects_pruned, - guint64 *out_pruned_object_size_total, - GCancellable *cancellable, - GError **error) +ostree_repo_prune (OstreeRepo *repo, + OstreeRepoPruneFlags flags, + gint depth, + gint *out_objects_total, + gint *out_objects_pruned, + guint64 *out_pruned_object_size_total, + GCancellable *cancellable, + GError **error) { gboolean ret = FALSE; GHashTableIter hash_iter; @@ -101,7 +101,7 @@ ostree_prune (OstreeRepo *repo, gs_unref_hashtable GHashTable *all_refs = NULL; gs_free char *formatted_freed_size = NULL; OtPruneData data; - gboolean refs_only = flags & OSTREE_PRUNE_FLAGS_REFS_ONLY; + gboolean refs_only = flags & OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY; memset (&data, 0, sizeof (data)); diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h index 8b5b55b0..998bf433 100644 --- a/src/libostree/ostree-repo.h +++ b/src/libostree/ostree-repo.h @@ -332,6 +332,20 @@ gboolean ostree_repo_traverse_commit (OstreeRepo *repo, GCancellable *cancellable, GError **error); +typedef enum { + OSTREE_REPO_PRUNE_FLAGS_NONE, + OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE, + OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY +} OstreeRepoPruneFlags; + +gboolean ostree_repo_prune (OstreeRepo *repo, + OstreeRepoPruneFlags flags, + gint depth, + gint *out_objects_total, + gint *out_objects_pruned, + guint64 *out_pruned_object_size_total, + GCancellable *cancellable, + GError **error); G_END_DECLS diff --git a/src/ostree/ostree-prune.h b/src/ostree/ostree-prune.h deleted file mode 100644 index 882fb603..00000000 --- a/src/ostree/ostree-prune.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- - * - * Copyright (C) 2013 Colin Walters - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2 of the licence or (at - * your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#pragma once - -#include "ostree.h" - -G_BEGIN_DECLS - -typedef enum { - OSTREE_PRUNE_FLAGS_NONE, - OSTREE_PRUNE_FLAGS_NO_PRUNE, - OSTREE_PRUNE_FLAGS_REFS_ONLY -} OstreePruneFlags; - -gboolean ostree_prune (OstreeRepo *repo, - OstreePruneFlags flags, - gint depth, - gint *out_objects_total, - gint *out_objects_pruned, - guint64 *out_pruned_object_size_total, - GCancellable *cancellable, - GError **error); - -G_END_DECLS - diff --git a/src/ostree/ot-admin-cleanup.c b/src/ostree/ot-admin-cleanup.c index 1ca242a7..d8d9e8e3 100644 --- a/src/ostree/ot-admin-cleanup.c +++ b/src/ostree/ot-admin-cleanup.c @@ -27,8 +27,7 @@ #include "ot-deployment.h" #include "ot-config-parser.h" #include "otutil.h" -#include "ostree-core.h" -#include "ostree-prune.h" +#include "ostree.h" #include "libgsystem.h" static gboolean @@ -463,9 +462,9 @@ generate_deployment_refs_and_prune (GFile *sysroot, goto out; } - if (!ostree_prune (repo, OSTREE_PRUNE_FLAGS_REFS_ONLY, 0, - &n_objects_total, &n_objects_pruned, &freed_space, - cancellable, error)) + if (!ostree_repo_prune (repo, OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY, 0, + &n_objects_total, &n_objects_pruned, &freed_space, + cancellable, error)) goto out; if (freed_space > 0) { diff --git a/src/ostree/ot-admin-functions.c b/src/ostree/ot-admin-functions.c index 1b469ebe..3780c2a9 100644 --- a/src/ostree/ot-admin-functions.c +++ b/src/ostree/ot-admin-functions.c @@ -28,8 +28,7 @@ #include "ot-config-parser.h" #include "ot-bootloader-syslinux.h" #include "otutil.h" -#include "ostree-core.h" -#include "ostree-prune.h" +#include "ostree.h" #include "libgsystem.h" OtOrderedHash * diff --git a/src/ostree/ot-builtin-prune.c b/src/ostree/ot-builtin-prune.c index f52153cb..3c0a68c7 100644 --- a/src/ostree/ot-builtin-prune.c +++ b/src/ostree/ot-builtin-prune.c @@ -23,7 +23,7 @@ #include "config.h" #include "ot-builtins.h" -#include "ostree-prune.h" +#include "ostree.h" #include #include @@ -47,7 +47,7 @@ ostree_builtin_prune (int argc, char **argv, GFile *repo_path, GError **error) GCancellable *cancellable = NULL; gs_unref_object OstreeRepo *repo = NULL; gs_free char *formatted_freed_size = NULL; - OstreePruneFlags pruneflags = 0; + OstreeRepoPruneFlags pruneflags = 0; gint n_objects_total; gint n_objects_pruned; guint64 objsize_total; @@ -63,13 +63,13 @@ ostree_builtin_prune (int argc, char **argv, GFile *repo_path, GError **error) goto out; if (opt_refs_only) - pruneflags |= OSTREE_PRUNE_FLAGS_REFS_ONLY; + pruneflags |= OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY; if (opt_no_prune) - pruneflags |= OSTREE_PRUNE_FLAGS_NO_PRUNE; + pruneflags |= OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE; - if (!ostree_prune (repo, pruneflags, opt_depth, - &n_objects_total, &n_objects_pruned, &objsize_total, - cancellable, error)) + if (!ostree_repo_prune (repo, pruneflags, opt_depth, + &n_objects_total, &n_objects_pruned, &objsize_total, + cancellable, error)) goto out; formatted_freed_size = g_format_size_full (objsize_total, 0); @@ -77,7 +77,7 @@ ostree_builtin_prune (int argc, char **argv, GFile *repo_path, GError **error) g_print ("Total objects: %u\n", n_objects_total); if (n_objects_pruned == 0) g_print ("No unreachable objects\n"); - else if (pruneflags & OSTREE_PRUNE_FLAGS_NO_PRUNE) + else if (pruneflags & OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE) g_print ("Would delete: %u objects, freeing %s bytes\n", n_objects_pruned, formatted_freed_size); else