lib/pull: A bit of new style porting
A lof of the functions here are async and have nontrivial exits, but these ones are all sync were straightforward ports. Not prep for anything, just chipping away at porting. Closes: #1146 Approved by: jlebon
This commit is contained in:
parent
db6135f5b3
commit
ea4d3d1ac4
|
|
@ -1588,6 +1588,9 @@ verify_bindings (OtPullData *pull_data,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Look at a commit object, and determine whether there are
|
||||||
|
* more things to fetch.
|
||||||
|
*/
|
||||||
static gboolean
|
static gboolean
|
||||||
scan_commit_object (OtPullData *pull_data,
|
scan_commit_object (OtPullData *pull_data,
|
||||||
const char *checksum,
|
const char *checksum,
|
||||||
|
|
@ -1596,19 +1599,8 @@ scan_commit_object (OtPullData *pull_data,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
/* If we found a legacy transaction flag, assume we have to scan.
|
|
||||||
* We always do a scan of dirtree objects; see
|
|
||||||
* https://github.com/ostreedev/ostree/issues/543
|
|
||||||
*/
|
|
||||||
OstreeRepoCommitState commitstate;
|
|
||||||
g_autoptr(GVariant) commit = NULL;
|
|
||||||
g_autoptr(GVariant) parent_csum = NULL;
|
|
||||||
const guchar *parent_csum_bytes = NULL;
|
|
||||||
gpointer depthp;
|
gpointer depthp;
|
||||||
gint depth;
|
gint depth;
|
||||||
gboolean is_partial;
|
|
||||||
|
|
||||||
if (g_hash_table_lookup_extended (pull_data->commit_to_depth, checksum,
|
if (g_hash_table_lookup_extended (pull_data->commit_to_depth, checksum,
|
||||||
NULL, &depthp))
|
NULL, &depthp))
|
||||||
{
|
{
|
||||||
|
|
@ -1631,20 +1623,23 @@ scan_commit_object (OtPullData *pull_data,
|
||||||
cancellable,
|
cancellable,
|
||||||
error);
|
error);
|
||||||
if (!process_verify_result (pull_data, checksum, result, error))
|
if (!process_verify_result (pull_data, checksum, result, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If we found a legacy transaction flag, assume we have to scan.
|
||||||
|
* We always do a scan of dirtree objects; see
|
||||||
|
* https://github.com/ostreedev/ostree/issues/543
|
||||||
|
*/
|
||||||
|
OstreeRepoCommitState commitstate;
|
||||||
|
g_autoptr(GVariant) commit = NULL;
|
||||||
if (!ostree_repo_load_commit (pull_data->repo, checksum, &commit, &commitstate, error))
|
if (!ostree_repo_load_commit (pull_data->repo, checksum, &commit, &commitstate, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
/* If ref is non-NULL then the commit we fetched was requested through the
|
/* If ref is non-NULL then the commit we fetched was requested through the
|
||||||
* branch, otherwise we requested a commit checksum without specifying a branch.
|
* branch, otherwise we requested a commit checksum without specifying a branch.
|
||||||
*/
|
*/
|
||||||
if (!verify_bindings (pull_data, commit, ref, error))
|
if (!verify_bindings (pull_data, commit, ref, error))
|
||||||
{
|
return glnx_prefix_error (error, "Commit %s", checksum);
|
||||||
g_prefix_error (error, "Commit %s: ", checksum);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pull_data->timestamp_check)
|
if (pull_data->timestamp_check)
|
||||||
{
|
{
|
||||||
|
|
@ -1661,28 +1656,27 @@ scan_commit_object (OtPullData *pull_data,
|
||||||
{
|
{
|
||||||
if (!ostree_repo_load_commit (pull_data->repo, orig_rev,
|
if (!ostree_repo_load_commit (pull_data->repo, orig_rev,
|
||||||
&orig_commit, NULL, error))
|
&orig_commit, NULL, error))
|
||||||
{
|
return glnx_prefix_error (error, "Reading %s for timestamp-check", ref->ref_name);
|
||||||
g_prefix_error (error, "Reading %s for timestamp-check: ", ref->ref_name);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
guint64 orig_ts = ostree_commit_get_timestamp (orig_commit);
|
guint64 orig_ts = ostree_commit_get_timestamp (orig_commit);
|
||||||
guint64 new_ts = ostree_commit_get_timestamp (commit);
|
guint64 new_ts = ostree_commit_get_timestamp (commit);
|
||||||
if (!_ostree_compare_timestamps (orig_rev, orig_ts, checksum, new_ts, error))
|
if (!_ostree_compare_timestamps (orig_rev, orig_ts, checksum, new_ts, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we found a legacy transaction flag, assume all commits are partial */
|
/* If we found a legacy transaction flag, assume all commits are partial */
|
||||||
is_partial = commitstate_is_partial (pull_data, commitstate);
|
gboolean is_partial = commitstate_is_partial (pull_data, commitstate);
|
||||||
|
|
||||||
/* PARSE OSTREE_SERIALIZED_COMMIT_VARIANT */
|
/* PARSE OSTREE_SERIALIZED_COMMIT_VARIANT */
|
||||||
|
g_autoptr(GVariant) parent_csum = NULL;
|
||||||
|
const guchar *parent_csum_bytes = NULL;
|
||||||
g_variant_get_child (commit, 1, "@ay", &parent_csum);
|
g_variant_get_child (commit, 1, "@ay", &parent_csum);
|
||||||
if (g_variant_n_children (parent_csum) > 0)
|
if (g_variant_n_children (parent_csum) > 0)
|
||||||
{
|
{
|
||||||
parent_csum_bytes = ostree_checksum_bytes_peek_validate (parent_csum, error);
|
parent_csum_bytes = ostree_checksum_bytes_peek_validate (parent_csum, error);
|
||||||
if (parent_csum_bytes == NULL)
|
if (parent_csum_bytes == NULL)
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent_csum_bytes != NULL && pull_data->maxdepth == -1)
|
if (parent_csum_bytes != NULL && pull_data->maxdepth == -1)
|
||||||
|
|
@ -1737,11 +1731,11 @@ scan_commit_object (OtPullData *pull_data,
|
||||||
|
|
||||||
tree_contents_csum_bytes = ostree_checksum_bytes_peek_validate (tree_contents_csum, error);
|
tree_contents_csum_bytes = ostree_checksum_bytes_peek_validate (tree_contents_csum, error);
|
||||||
if (tree_contents_csum_bytes == NULL)
|
if (tree_contents_csum_bytes == NULL)
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
tree_meta_csum_bytes = ostree_checksum_bytes_peek_validate (tree_meta_csum, error);
|
tree_meta_csum_bytes = ostree_checksum_bytes_peek_validate (tree_meta_csum, error);
|
||||||
if (tree_meta_csum_bytes == NULL)
|
if (tree_meta_csum_bytes == NULL)
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
queue_scan_one_metadata_object_c (pull_data, tree_contents_csum_bytes,
|
queue_scan_one_metadata_object_c (pull_data, tree_contents_csum_bytes,
|
||||||
OSTREE_OBJECT_TYPE_DIR_TREE, "/", recursion_depth + 1, NULL);
|
OSTREE_OBJECT_TYPE_DIR_TREE, "/", recursion_depth + 1, NULL);
|
||||||
|
|
@ -1750,9 +1744,7 @@ scan_commit_object (OtPullData *pull_data,
|
||||||
OSTREE_OBJECT_TYPE_DIR_META, NULL, recursion_depth + 1, NULL);
|
OSTREE_OBJECT_TYPE_DIR_META, NULL, recursion_depth + 1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
return TRUE;
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -2532,22 +2524,11 @@ static gboolean
|
||||||
validate_variant_is_csum (GVariant *csum,
|
validate_variant_is_csum (GVariant *csum,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
|
|
||||||
if (!g_variant_is_of_type (csum, G_VARIANT_TYPE ("ay")))
|
if (!g_variant_is_of_type (csum, G_VARIANT_TYPE ("ay")))
|
||||||
{
|
return glnx_throw (error, "Invalid checksum variant of type '%s', expected 'ay'",
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
g_variant_get_type_string (csum));
|
||||||
"Invalid checksum variant of type '%s', expected 'ay'",
|
|
||||||
g_variant_get_type_string (csum));
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ostree_validate_structureof_csum_v (csum, error))
|
return ostree_validate_structureof_csum_v (csum, error);
|
||||||
goto out;
|
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load the summary from the cache if the provided .sig file is the same as the
|
/* Load the summary from the cache if the provided .sig file is the same as the
|
||||||
|
|
@ -2560,27 +2541,19 @@ _ostree_repo_load_cache_summary_if_same_sig (OstreeRepo *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
const char *summary_cache_sig_file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", remote, ".sig");
|
|
||||||
|
|
||||||
glnx_fd_close int prev_fd = -1;
|
|
||||||
g_autoptr(GBytes) old_sig_contents = NULL;
|
|
||||||
|
|
||||||
if (self->cache_dir_fd == -1)
|
if (self->cache_dir_fd == -1)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
const char *summary_cache_sig_file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", remote, ".sig");
|
||||||
|
glnx_fd_close int prev_fd = -1;
|
||||||
if (!ot_openat_ignore_enoent (self->cache_dir_fd, summary_cache_sig_file, &prev_fd, error))
|
if (!ot_openat_ignore_enoent (self->cache_dir_fd, summary_cache_sig_file, &prev_fd, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
if (prev_fd < 0)
|
if (prev_fd < 0)
|
||||||
{
|
return TRUE; /* Note early return */
|
||||||
ret = TRUE;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
old_sig_contents = glnx_fd_readall_bytes (prev_fd, cancellable, error);
|
g_autoptr(GBytes) old_sig_contents = glnx_fd_readall_bytes (prev_fd, cancellable, error);
|
||||||
if (!old_sig_contents)
|
if (!old_sig_contents)
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
if (g_bytes_compare (old_sig_contents, summary_sig) == 0)
|
if (g_bytes_compare (old_sig_contents, summary_sig) == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -2595,25 +2568,21 @@ _ostree_repo_load_cache_summary_if_same_sig (OstreeRepo *self,
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
{
|
{
|
||||||
(void) unlinkat (self->cache_dir_fd, summary_cache_sig_file, 0);
|
(void) unlinkat (self->cache_dir_fd, summary_cache_sig_file, 0);
|
||||||
ret = TRUE;
|
return TRUE; /* Note early return */
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glnx_set_error_from_errno (error);
|
return glnx_throw_errno_prefix (error, "openat(%s)", summary_cache_file);
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
summary_data = glnx_fd_readall_bytes (summary_fd, cancellable, error);
|
summary_data = glnx_fd_readall_bytes (summary_fd, cancellable, error);
|
||||||
if (!summary_data)
|
if (!summary_data)
|
||||||
goto out;
|
return FALSE;
|
||||||
*summary = summary_data;
|
*summary = summary_data;
|
||||||
}
|
}
|
||||||
ret = TRUE;
|
return TRUE;
|
||||||
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Replace the current summary+signature with new versions */
|
||||||
static gboolean
|
static gboolean
|
||||||
_ostree_repo_cache_summary (OstreeRepo *self,
|
_ostree_repo_cache_summary (OstreeRepo *self,
|
||||||
const char *remote,
|
const char *remote,
|
||||||
|
|
@ -2622,36 +2591,31 @@ _ostree_repo_cache_summary (OstreeRepo *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
const char *summary_cache_file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", remote);
|
|
||||||
const char *summary_cache_sig_file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", remote, ".sig");
|
|
||||||
|
|
||||||
if (self->cache_dir_fd == -1)
|
if (self->cache_dir_fd == -1)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
if (!glnx_shutil_mkdir_p_at (self->cache_dir_fd, _OSTREE_SUMMARY_CACHE_DIR, 0775, cancellable, error))
|
if (!glnx_shutil_mkdir_p_at (self->cache_dir_fd, _OSTREE_SUMMARY_CACHE_DIR, 0775, cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
|
const char *summary_cache_file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", remote);
|
||||||
if (!glnx_file_replace_contents_at (self->cache_dir_fd,
|
if (!glnx_file_replace_contents_at (self->cache_dir_fd,
|
||||||
summary_cache_file,
|
summary_cache_file,
|
||||||
g_bytes_get_data (summary, NULL),
|
g_bytes_get_data (summary, NULL),
|
||||||
g_bytes_get_size (summary),
|
g_bytes_get_size (summary),
|
||||||
self->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : GLNX_FILE_REPLACE_DATASYNC_NEW,
|
self->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : GLNX_FILE_REPLACE_DATASYNC_NEW,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
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,
|
if (!glnx_file_replace_contents_at (self->cache_dir_fd,
|
||||||
summary_cache_sig_file,
|
summary_cache_sig_file,
|
||||||
g_bytes_get_data (summary_sig, NULL),
|
g_bytes_get_data (summary_sig, NULL),
|
||||||
g_bytes_get_size (summary_sig),
|
g_bytes_get_size (summary_sig),
|
||||||
self->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : GLNX_FILE_REPLACE_DATASYNC_NEW,
|
self->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : GLNX_FILE_REPLACE_DATASYNC_NEW,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static OstreeFetcher *
|
static OstreeFetcher *
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue