@@ -278,19 +278,31 @@ otcore_load_rootfs_config (const char *cmdline, GKeyFile *config, gboolean load_
278278}
279279
280280#ifdef HAVE_COMPOSEFS
281- static GVariant *
281+ static gboolean
282282load_variant (const char * root_mountpoint , const char * digest , const char * extension ,
283- const GVariantType * type , GError * * error )
283+ const GVariantType * type , gboolean allow_noent , GVariant * * out , GError * * error )
284284{
285285 g_autofree char * path = g_strdup_printf ("%s/ostree/repo/objects/%.2s/%s.%s" , root_mountpoint ,
286286 digest , digest + 2 , extension );
287287
288288 char * data = NULL ;
289289 gsize data_size ;
290- if (!g_file_get_contents (path , & data , & data_size , error ))
291- return NULL ;
290+ g_autoptr (GError ) local_error = NULL ;
291+
292+ if (!g_file_get_contents (path , & data , & data_size , & local_error ))
293+ {
294+ if (allow_noent && g_error_matches (local_error , G_FILE_ERROR , G_FILE_ERROR_NOENT ))
295+ {
296+ * out = NULL ;
297+ return TRUE;
298+ }
299+
300+ g_propagate_error (error , g_steal_pointer (& local_error ));
301+ return FALSE;
302+ }
292303
293- return g_variant_ref_sink (g_variant_new_from_data (type , data , data_size , FALSE, g_free , data ));
304+ * out = g_variant_ref_sink (g_variant_new_from_data (type , data , data_size , FALSE, g_free , data ));
305+ return TRUE;
294306}
295307
296308// Given a mount point, directly load the .commit object. At the current time this tool
@@ -299,27 +311,21 @@ static gboolean
299311load_commit_for_deploy (const char * root_mountpoint , const char * deploy_path , GVariant * * commit_out ,
300312 GVariant * * commitmeta_out , GError * * error )
301313{
302- g_autoptr (GError ) local_error = NULL ;
303314 g_autofree char * digest = g_path_get_basename (deploy_path );
304315 char * dot = strchr (digest , '.' );
305316 if (dot != NULL )
306317 * dot = 0 ;
307318
308- g_autoptr (GVariant ) commit_v
309- = load_variant (root_mountpoint , digest , "commit" , OSTREE_COMMIT_GVARIANT_FORMAT , error );
310- if (commit_v == NULL )
319+ g_autoptr (GVariant ) commit_v = NULL ;
320+ g_autoptr (GVariant ) commitmeta_v = NULL ;
321+
322+ if (!load_variant (root_mountpoint , digest , "commit" , OSTREE_COMMIT_GVARIANT_FORMAT , FALSE,
323+ & commit_v , error ))
311324 return FALSE;
312325
313- g_autoptr (GVariant ) commitmeta_v = load_variant (root_mountpoint , digest , "commitmeta" ,
314- G_VARIANT_TYPE ("a{sv}" ), & local_error );
315- if (commitmeta_v == NULL )
316- {
317- if (g_error_matches (local_error , G_FILE_ERROR , G_FILE_ERROR_NOENT ))
318- glnx_throw (error , "No commitmeta for commit %s" , digest );
319- else
320- g_propagate_error (error , g_steal_pointer (& local_error ));
321- return FALSE;
322- }
326+ if (!load_variant (root_mountpoint , digest , "commitmeta" , G_VARIANT_TYPE ("a{sv}" ), TRUE,
327+ & commitmeta_v , error ))
328+ return FALSE;
323329
324330 * commit_out = g_steal_pointer (& commit_v );
325331 * commitmeta_out = g_steal_pointer (& commitmeta_v );
@@ -553,9 +559,13 @@ otcore_mount_rootfs (RootConfig *rootfs_config, GVariantBuilder *metadata_builde
553559 g_autoptr (GVariant ) commit = NULL ;
554560 g_autoptr (GVariant ) commitmeta = NULL ;
555561
556- if (!load_commit_for_deploy (root_mountpoint , deploy_path , & commit , & commitmeta , error ))
562+ if (!load_commit_for_deploy (root_mountpoint , deploy_path , & commit , & commitmeta ,
563+ error ))
557564 return glnx_prefix_error (error , "Error loading signatures from repo" );
558565
566+ if (commitmeta == NULL )
567+ return glnx_throw (error , "No commitmeta for deploy %s" , deploy_path );
568+
559569 g_autoptr (GVariant ) signatures = g_variant_lookup_value (
560570 commitmeta , OSTREE_SIGN_METADATA_ED25519_KEY , G_VARIANT_TYPE ("aay" ));
561571 if (signatures == NULL )
0 commit comments