mirror of
https://github.com/ostreedev/ostree.git
synced 2025-03-19 22:50:35 +03:00
Add OstreeRepo option for an out-of-band cache dir
This allows you to have a writable cache dir even for a system-owned repository. Closes: #250 Approved by: cgwalters
This commit is contained in:
parent
b787fce612
commit
9e7e594907
@ -335,4 +335,5 @@ global:
|
||||
ostree_repo_get_remote_option;
|
||||
ostree_repo_get_remote_list_option;
|
||||
ostree_repo_get_remote_boolean_option;
|
||||
ostree_repo_set_cache_dir;
|
||||
} LIBOSTREE_2016.4;
|
||||
|
@ -54,6 +54,7 @@ struct OstreeRepo {
|
||||
GFile *tmp_dir;
|
||||
int tmp_dir_fd;
|
||||
int cache_dir_fd;
|
||||
char *cache_dir;
|
||||
GFile *objects_dir;
|
||||
GFile *state_dir;
|
||||
int objects_dir_fd;
|
||||
|
@ -2573,6 +2573,36 @@ ostree_repo_set_disable_fsync (OstreeRepo *self,
|
||||
self->disable_fsync = disable_fsync;
|
||||
}
|
||||
|
||||
/**
|
||||
* ostree_repo_set_cache_dir:
|
||||
* @self: An #OstreeRepo
|
||||
* @dfd: directory fd
|
||||
* @path: subpath in @dfd
|
||||
*
|
||||
* Set a custom location for the cache directory used for e.g.
|
||||
* per-remote summary caches. Setting this manually is useful when
|
||||
* doing operations on a system repo as a user because you don't have
|
||||
* write permissions in the repo, where the cache is normally stored.
|
||||
*/
|
||||
gboolean
|
||||
ostree_repo_set_cache_dir (OstreeRepo *self,
|
||||
int dfd,
|
||||
const char *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (!glnx_opendirat (dfd, path, TRUE, &fd, error))
|
||||
return FALSE;
|
||||
|
||||
if (self->cache_dir_fd != -1)
|
||||
close (self->cache_dir_fd);
|
||||
self->cache_dir_fd = fd;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* ostree_repo_get_disable_fsync:
|
||||
* @self: An #OstreeRepo
|
||||
|
@ -63,6 +63,13 @@ _OSTREE_PUBLIC
|
||||
void ostree_repo_set_disable_fsync (OstreeRepo *self,
|
||||
gboolean disable_fsync);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_repo_set_cache_dir (OstreeRepo *self,
|
||||
int dfd,
|
||||
const char *path,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_repo_get_disable_fsync (OstreeRepo *self);
|
||||
|
||||
|
@ -35,10 +35,12 @@ static gboolean opt_disable_static_deltas;
|
||||
static gboolean opt_require_static_deltas;
|
||||
static gboolean opt_untrusted;
|
||||
static char* opt_subpath;
|
||||
static char* opt_cache_dir;
|
||||
static int opt_depth = 0;
|
||||
|
||||
static GOptionEntry options[] = {
|
||||
{ "commit-metadata-only", 0, 0, G_OPTION_ARG_NONE, &opt_commit_only, "Fetch only the commit metadata", NULL },
|
||||
{ "cache-dir", 0, 0, G_OPTION_ARG_STRING, &opt_cache_dir, "Use custom cache dir", NULL },
|
||||
{ "disable-fsync", 0, 0, G_OPTION_ARG_NONE, &opt_disable_fsync, "Do not invoke fsync()", NULL },
|
||||
{ "disable-static-deltas", 0, 0, G_OPTION_ARG_NONE, &opt_disable_static_deltas, "Do not use static deltas", NULL },
|
||||
{ "require-static-deltas", 0, 0, G_OPTION_ARG_NONE, &opt_require_static_deltas, "Require static deltas", NULL },
|
||||
@ -130,6 +132,12 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **
|
||||
if (opt_disable_fsync)
|
||||
ostree_repo_set_disable_fsync (repo, TRUE);
|
||||
|
||||
if (opt_cache_dir)
|
||||
{
|
||||
if (!ostree_repo_set_cache_dir (repo, AT_FDCWD, opt_cache_dir, cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (opt_mirror)
|
||||
pullflags |= OSTREE_REPO_PULL_FLAGS_MIRROR;
|
||||
|
||||
|
@ -25,7 +25,10 @@
|
||||
#include "ot-main.h"
|
||||
#include "ot-remote-builtins.h"
|
||||
|
||||
static char* opt_cache_dir;
|
||||
|
||||
static GOptionEntry option_entries[] = {
|
||||
{ "cache-dir", 0, 0, G_OPTION_ARG_STRING, &opt_cache_dir, "Use custom cache dir", NULL },
|
||||
};
|
||||
|
||||
gboolean
|
||||
@ -49,6 +52,12 @@ ot_remote_builtin_refs (int argc, char **argv, GCancellable *cancellable, GError
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (opt_cache_dir)
|
||||
{
|
||||
if (!ostree_repo_set_cache_dir (repo, AT_FDCWD, opt_cache_dir, cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
|
||||
remote_name = argv[1];
|
||||
|
||||
if (!ostree_repo_remote_list_refs (repo, remote_name, &refs, cancellable, error))
|
||||
|
@ -28,7 +28,10 @@
|
||||
|
||||
static gboolean opt_raw;
|
||||
|
||||
static char* opt_cache_dir;
|
||||
|
||||
static GOptionEntry option_entries[] = {
|
||||
{ "cache-dir", 0, 0, G_OPTION_ARG_STRING, &opt_cache_dir, "Use custom cache dir", NULL },
|
||||
{ "raw", 0, 0, G_OPTION_ARG_NONE, &opt_raw, "Show raw variant data", NULL },
|
||||
{ NULL }
|
||||
};
|
||||
@ -59,6 +62,12 @@ ot_remote_builtin_summary (int argc, char **argv, GCancellable *cancellable, GEr
|
||||
|
||||
remote_name = argv[1];
|
||||
|
||||
if (opt_cache_dir)
|
||||
{
|
||||
if (!ostree_repo_set_cache_dir (repo, AT_FDCWD, opt_cache_dir, cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (opt_raw)
|
||||
flags |= OSTREE_DUMP_RAW;
|
||||
|
||||
|
@ -21,7 +21,7 @@ set -euo pipefail
|
||||
|
||||
. $(dirname $0)/libtest.sh
|
||||
|
||||
echo "1..6"
|
||||
echo "1..7"
|
||||
|
||||
COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
|
||||
setup_fake_remote_repo1 "archive-z2" "${COMMIT_SIGN}"
|
||||
@ -91,6 +91,21 @@ assert_has_file repo/tmp/cache/summaries/origin
|
||||
assert_has_file repo/tmp/cache/summaries/origin.sig
|
||||
echo "ok prune summary cache"
|
||||
|
||||
cd ${test_tmpdir}
|
||||
repo_reinit
|
||||
mkdir cachedir
|
||||
${OSTREE} --repo=repo pull --cache-dir=cachedir origin main
|
||||
assert_not_has_file repo/tmp/cache/summaries/origin
|
||||
assert_not_has_file repo/tmp/cache/summaries/origin.sig
|
||||
assert_has_file cachedir/summaries/origin
|
||||
assert_has_file cachedir/summaries/origin.sig
|
||||
|
||||
rm cachedir/summaries/origin
|
||||
${OSTREE} --repo=repo pull --cache-dir=cachedir origin main
|
||||
assert_not_has_file repo/tmp/cache/summaries/origin
|
||||
assert_has_file cachedir/summaries/origin
|
||||
|
||||
echo "ok pull with signed summary and cachedir"
|
||||
|
||||
cd ${test_tmpdir}
|
||||
repo_reinit
|
||||
|
Loading…
x
Reference in New Issue
Block a user