libpriv: Add RpmOstreeRefTs and API to create one from a commit

This API is intended for use by the caching framework to hold open an
rpmdb for the previous commit.
This commit is contained in:
Colin Walters 2015-05-22 10:54:41 -04:00
parent b378386e98
commit 70f5b535e4
5 changed files with 151 additions and 0 deletions

View File

@ -26,6 +26,8 @@ librpmostreepriv_la_SOURCES = \
src/libpriv/rpmostree-util.h \ src/libpriv/rpmostree-util.h \
src/libpriv/rpmostree-passwd-util.c \ src/libpriv/rpmostree-passwd-util.c \
src/libpriv/rpmostree-passwd-util.h \ src/libpriv/rpmostree-passwd-util.h \
src/libpriv/rpmostree-refts.h \
src/libpriv/rpmostree-refts.c \
src/libpriv/rpmostree-refsack.h \ src/libpriv/rpmostree-refsack.h \
src/libpriv/rpmostree-refsack.c \ src/libpriv/rpmostree-refsack.c \
src/libpriv/rpmostree-cleanup.h \ src/libpriv/rpmostree-cleanup.h \

View File

@ -0,0 +1,64 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2015 Colin Walters <walters@verbum.org>
*
* 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.
*/
#include "config.h"
#include <string.h>
#include "rpmostree-refts.h"
#include "rpmostree-rpm-util.h"
/*
* A wrapper for an `rpmts` that supports:
*
* - Reference counting
* - Possibly holding a pointer to a tempdir, and cleaning it when unref'd
*/
RpmOstreeRefTs *
rpmostree_refts_new (rpmts ts, int temp_base_dfd, const char *temp_path)
{
RpmOstreeRefTs *rts = g_new0 (RpmOstreeRefTs, 1);
rts->ts = ts;
rts->refcount = 1;
rts->temp_base_dfd = temp_base_dfd;
rts->temp_path = g_strdup (temp_path);
return rts;
}
RpmOstreeRefTs *
rpmostree_refts_ref (RpmOstreeRefTs *rts)
{
g_atomic_int_inc (&rts->refcount);
return rts;
}
void
rpmostree_refts_unref (RpmOstreeRefTs *rts)
{
if (!g_atomic_int_dec_and_test (&rts->refcount))
return;
rpmtsFree (rts->ts);
if (rts->temp_path)
(void) glnx_shutil_rm_rf_at (rts->temp_base_dfd, rts->temp_path, NULL, NULL);
g_free (rts->temp_path);
g_free (rts);
}

View File

@ -0,0 +1,45 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2015 Red Hat, In.c
*
* Licensed under the GNU Lesser General Public License Version 2.1
*
* This library 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.1 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include <hawkey/package.h>
#include <hawkey/sack.h>
#include "rpmostree-cleanup.h"
typedef struct {
volatile gint refcount;
rpmts ts;
int temp_base_dfd;
char *temp_path;
} RpmOstreeRefTs;
RpmOstreeRefTs *
rpmostree_refts_new (rpmts ts, int temp_base_dfd, const char *temp_path);
RpmOstreeRefTs *
rpmostree_refts_ref (RpmOstreeRefTs *rts);
void
rpmostree_refts_unref (RpmOstreeRefTs *rts);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(RpmOstreeRefTs, rpmostree_refts_unref);

View File

@ -869,6 +869,38 @@ rpmostree_get_refsack_for_commit (OstreeRepo *repo,
return ret; return ret;
} }
gboolean
rpmostree_get_refts_for_commit (OstreeRepo *repo,
const char *ref,
RpmOstreeRefTs **out_ts,
GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
g_autofree char *tempdir = NULL;
rpmts ts;
int r;
if (!rpmostree_checkout_only_rpmdb_tempdir (repo, ref, &tempdir, NULL,
cancellable, error))
goto out;
ts = rpmtsCreate ();
/* This actually makes sense because we know we've verified it at build time */
rpmtsSetVSFlags (ts, _RPMVSF_NODIGESTS | _RPMVSF_NOSIGNATURES);
r = rpmtsSetRootDir (ts, tempdir);
g_assert_cmpint (r, ==, 0);
ret = TRUE;
*out_ts = rpmostree_refts_new (ts, AT_FDCWD, tempdir);
g_clear_pointer (&tempdir, g_free);
out:
if (tempdir)
(void) glnx_shutil_rm_rf_at (AT_FDCWD, tempdir, NULL, NULL);
return ret;
}
gboolean gboolean
rpmostree_get_pkglist_for_root (int dfd, rpmostree_get_pkglist_for_root (int dfd,
const char *path, const char *path,

View File

@ -26,6 +26,7 @@
#include <rpm/rpmlog.h> #include <rpm/rpmlog.h>
#include "rpmostree-util.h" #include "rpmostree-util.h"
#include "rpmostree-refsack.h" #include "rpmostree-refsack.h"
#include "rpmostree-refts.h"
#include "rpmostree-cleanup.h" #include "rpmostree-cleanup.h"
#include "libglnx.h" #include "libglnx.h"
@ -101,6 +102,13 @@ rpmostree_get_refsack_for_root (int dfd,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);
gboolean
rpmostree_get_refts_for_commit (OstreeRepo *repo,
const char *ref,
RpmOstreeRefTs **out_ts,
GCancellable *cancellable,
GError **error);
gboolean gboolean
rpmostree_get_pkglist_for_root (int dfd, rpmostree_get_pkglist_for_root (int dfd,
const char *path, const char *path,