lib/core: add ostree_checksum_file_at API
This is like `ostree_checksum_file` but fd-relative. This will be used by https://github.com/ostreedev/ostree/pull/1258. AFAICT, we actually didn't have any tests that check the `checksum` CLI. Add a basic one here to test the old code as well as the new code. Closes: #1263 Approved by: cgwalters
This commit is contained in:
1 parent
60b5925c54
commit
077d2718ad
8 files changed
+173
-15
No files matched your search
@@ -32,7 +32,10 @@
|
||||
* man page (man/ostree-checksum.xml) when changing the option list.
|
||||
*/
|
||||
|
||||
static gboolean opt_ignore_xattrs;
|
||||
|
||||
static GOptionEntry options[] = {
|
||||
{ "ignore-xattrs", 0, 0, G_OPTION_ARG_NONE, &opt_ignore_xattrs, "Don't include xattrs in checksum", NULL },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
@@ -49,12 +52,14 @@ on_checksum_received (GObject *obj,
|
||||
{
|
||||
AsyncChecksumData *data = user_data;
|
||||
|
||||
g_autofree guchar *csum = NULL;
|
||||
data->success = ostree_checksum_file_async_finish ((GFile*)obj, result, &csum, data->error);
|
||||
g_autofree guchar *csum_bytes = NULL;
|
||||
data->success =
|
||||
ostree_checksum_file_async_finish ((GFile*)obj, result, &csum_bytes, data->error);
|
||||
if (data->success)
|
||||
{
|
||||
g_autofree char *checksum = ostree_checksum_from_bytes (csum);
|
||||
g_print ("%s\n", checksum);
|
||||
char csum[OSTREE_SHA256_STRING_LEN+1];
|
||||
ostree_checksum_inplace_from_bytes (csum_bytes, csum);
|
||||
g_print ("%s\n", csum);
|
||||
}
|
||||
|
||||
g_main_loop_quit (data->loop);
|
||||
@@ -73,15 +78,28 @@ ostree_builtin_checksum (int argc, char **argv, GCancellable *cancellable, GErro
|
||||
return glnx_throw (error, "A filename must be given");
|
||||
const char *path = argv[1];
|
||||
|
||||
g_autoptr(GFile) f = g_file_new_for_path (path);
|
||||
g_autoptr(GMainLoop) loop = g_main_loop_new (NULL, FALSE);
|
||||
/* for test coverage, use the async API if no flags are needed */
|
||||
if (!opt_ignore_xattrs)
|
||||
{
|
||||
g_autoptr(GFile) f = g_file_new_for_path (path);
|
||||
g_autoptr(GMainLoop) loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
AsyncChecksumData data = { 0, };
|
||||
AsyncChecksumData data = { 0, };
|
||||
|
||||
data.loop = loop;
|
||||
data.error = error;
|
||||
ostree_checksum_file_async (f, OSTREE_OBJECT_TYPE_FILE, G_PRIORITY_DEFAULT, cancellable,
|
||||
on_checksum_received, &data);
|
||||
g_main_loop_run (data.loop);
|
||||
return data.success;
|
||||
data.loop = loop;
|
||||
data.error = error;
|
||||
ostree_checksum_file_async (f, OSTREE_OBJECT_TYPE_FILE, G_PRIORITY_DEFAULT,
|
||||
cancellable, on_checksum_received, &data);
|
||||
g_main_loop_run (data.loop);
|
||||
return data.success;
|
||||
}
|
||||
|
||||
g_autofree char *checksum = NULL;
|
||||
if (!ostree_checksum_file_at (AT_FDCWD, path, NULL, OSTREE_OBJECT_TYPE_FILE,
|
||||
OSTREE_CHECKSUM_FLAGS_IGNORE_XATTRS, &checksum,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
g_print ("%s\n", checksum);
|
||||
return TRUE;
|
||||
}
|
||||
Reference in new issue
Block a user