From: Alexander Larsson Date: Fri, 11 Sep 2020 09:22:49 +0000 (+0200) Subject: pull: Break out _ostree_repo_save_cache_summary_file() helper X-Git-Tag: archive/raspbian/2022.1-3+rpi1~1^2~4^2~7^2~18^2~11 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=85accb84e87a4964a0fff02b28117a1e6b137c39;p=ostree.git pull: Break out _ostree_repo_save_cache_summary_file() helper This is a minor cleanup as its just called twice from _ostree_repo_cache_summary(). However, later code will need it in more places. --- diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c index d817575b..0e342568 100644 --- a/src/libostree/ostree-repo-pull.c +++ b/src/libostree/ostree-repo-pull.c @@ -2677,37 +2677,49 @@ _ostree_repo_load_cache_summary_if_same_sig (OstreeRepo *self, return TRUE; } -/* Replace the current summary+signature with new versions */ static gboolean -_ostree_repo_cache_summary (OstreeRepo *self, - const char *remote, - GBytes *summary, - GBytes *summary_sig, - GCancellable *cancellable, - GError **error) +_ostree_repo_save_cache_summary_file (OstreeRepo *self, + const char *filename, + const char *extension, + GBytes *data, + GCancellable *cancellable, + GError **error) { + const char *file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", filename, extension); + glnx_autofd int fd = -1; + if (self->cache_dir_fd == -1) return TRUE; if (!glnx_shutil_mkdir_p_at (self->cache_dir_fd, _OSTREE_SUMMARY_CACHE_DIR, DEFAULT_DIRECTORY_MODE, cancellable, error)) return FALSE; - const char *summary_cache_file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", remote); if (!glnx_file_replace_contents_at (self->cache_dir_fd, - summary_cache_file, - g_bytes_get_data (summary, NULL), - g_bytes_get_size (summary), + file, + g_bytes_get_data (data, NULL), + g_bytes_get_size (data), self->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : GLNX_FILE_REPLACE_DATASYNC_NEW, cancellable, error)) return FALSE; - const char *summary_cache_sig_file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", remote, ".sig"); - if (!glnx_file_replace_contents_at (self->cache_dir_fd, - summary_cache_sig_file, - g_bytes_get_data (summary_sig, NULL), - g_bytes_get_size (summary_sig), - self->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : GLNX_FILE_REPLACE_DATASYNC_NEW, - cancellable, error)) + return TRUE; +} + +/* Replace the current summary+signature with new versions */ +static gboolean +_ostree_repo_cache_summary (OstreeRepo *self, + const char *remote, + GBytes *summary, + GBytes *summary_sig, + GCancellable *cancellable, + GError **error) +{ + if (!_ostree_repo_save_cache_summary_file (self, remote, NULL, + summary, cancellable, error)) + return FALSE; + + if (!_ostree_repo_save_cache_summary_file (self, remote, ".sig", + summary_sig, cancellable, error)) return FALSE; return TRUE;