[ostree: 63/70] Add OstreeRepo option for an out-of-band cache dir
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree: 63/70] Add OstreeRepo option for an out-of-band cache dir
- Date: Fri, 15 Apr 2016 21:06:32 +0000 (UTC)
commit 9e7e594907cad21b7f5d843340948c4d426e8680
Author: Alexander Larsson <alexl redhat com>
Date: Mon Apr 11 12:43:07 2016 +0200
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
src/libostree/libostree.sym | 1 +
src/libostree/ostree-repo-private.h | 1 +
src/libostree/ostree-repo.c | 30 ++++++++++++++++++++++++++++++
src/libostree/ostree-repo.h | 7 +++++++
src/ostree/ot-builtin-pull.c | 8 ++++++++
src/ostree/ot-remote-builtin-refs.c | 9 +++++++++
src/ostree/ot-remote-builtin-summary.c | 9 +++++++++
tests/test-pull-summary-sigs.sh | 17 ++++++++++++++++-
8 files changed, 81 insertions(+), 1 deletions(-)
---
diff --git a/src/libostree/libostree.sym b/src/libostree/libostree.sym
index ea18632..89a1457 100644
--- a/src/libostree/libostree.sym
+++ b/src/libostree/libostree.sym
@@ -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;
diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h
index 1cf99ea..a2a9969 100644
--- a/src/libostree/ostree-repo-private.h
+++ b/src/libostree/ostree-repo-private.h
@@ -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;
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index b8cb242..495e226 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -2574,6 +2574,36 @@ ostree_repo_set_disable_fsync (OstreeRepo *self,
}
/**
+ * 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
*
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 822014f..8a04e8e 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -64,6 +64,13 @@ 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);
_OSTREE_PUBLIC
diff --git a/src/ostree/ot-builtin-pull.c b/src/ostree/ot-builtin-pull.c
index 8bef63a..734f744 100644
--- a/src/ostree/ot-builtin-pull.c
+++ b/src/ostree/ot-builtin-pull.c
@@ -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;
diff --git a/src/ostree/ot-remote-builtin-refs.c b/src/ostree/ot-remote-builtin-refs.c
index d21b19c..da3bcbb 100644
--- a/src/ostree/ot-remote-builtin-refs.c
+++ b/src/ostree/ot-remote-builtin-refs.c
@@ -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))
diff --git a/src/ostree/ot-remote-builtin-summary.c b/src/ostree/ot-remote-builtin-summary.c
index da76017..4659dd4 100644
--- a/src/ostree/ot-remote-builtin-summary.c
+++ b/src/ostree/ot-remote-builtin-summary.c
@@ -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;
diff --git a/tests/test-pull-summary-sigs.sh b/tests/test-pull-summary-sigs.sh
index 40de0a6..65822d2 100755
--- a/tests/test-pull-summary-sigs.sh
+++ b/tests/test-pull-summary-sigs.sh
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]