@@ -145,6 +145,29 @@ print_deployment_diff (OstreeRepo *repo, const char *from_desc, OstreeDeployment
145145 return print_diff (repo , from_desc , from_checksum , to_desc , to_checksum , cancellable , error );
146146}
147147
148+ static gboolean
149+ load_booted_deployment (const char * sysroot_path ,
150+ OstreeSysroot * * out_sysroot ,
151+ OstreeDeployment * * out_booted ,
152+ GCancellable * cancellable ,
153+ GError * * error )
154+ {
155+ g_autoptr (GFile ) sysroot_file = g_file_new_for_path (sysroot_path );
156+ g_autoptr (OstreeSysroot ) sysroot = ostree_sysroot_new (sysroot_file );
157+ if (!ostree_sysroot_load (sysroot , cancellable , error ))
158+ return FALSE;
159+
160+ OstreeDeployment * booted = ostree_sysroot_get_booted_deployment (sysroot );
161+ if (!booted )
162+ return glnx_throw (error , "Not booted into any deployment" );
163+
164+ if (out_sysroot )
165+ * out_sysroot = (OstreeSysroot * ) g_steal_pointer (& sysroot );
166+ if (out_booted )
167+ * out_booted = booted ;
168+ return TRUE;
169+ }
170+
148171gboolean
149172rpmostree_db_builtin_diff (int argc , char * * argv , RpmOstreeCommandInvocation * invocation ,
150173 GCancellable * cancellable , GError * * error )
@@ -228,15 +251,11 @@ rpmostree_db_builtin_diff (int argc, char **argv, RpmOstreeCommandInvocation *in
228251
229252 if (argc < 1 )
230253 {
231- g_autoptr (GFile ) sysroot_file = g_file_new_for_path ( sysroot_path ) ;
232- g_autoptr ( OstreeSysroot ) sysroot = ostree_sysroot_new ( sysroot_file ) ;
233- if (!ostree_sysroot_load ( sysroot , cancellable , error ))
254+ g_autoptr (OstreeSysroot ) sysroot = NULL ;
255+ OstreeDeployment * booted = NULL ;
256+ if (!load_booted_deployment ( sysroot_path , & sysroot , & booted , cancellable , error ))
234257 return FALSE;
235258
236- OstreeDeployment * booted = ostree_sysroot_get_booted_deployment (sysroot );
237- if (!booted )
238- return glnx_throw (error , "Not booted into any deployment" );
239-
240259 from_desc = "booted deployment" ;
241260 if (!get_checksum_from_deployment (repo , booted , & from_checksum , error ))
242261 return FALSE;
@@ -252,15 +271,11 @@ rpmostree_db_builtin_diff (int argc, char **argv, RpmOstreeCommandInvocation *in
252271 {
253272 /* find booted deployment */
254273 const char * sysroot_path = opt_sysroot ?: "/" ;
255- g_autoptr (GFile ) sysroot_file = g_file_new_for_path ( sysroot_path ) ;
256- g_autoptr ( OstreeSysroot ) sysroot = ostree_sysroot_new ( sysroot_file ) ;
257- if (!ostree_sysroot_load ( sysroot , cancellable , error ))
274+ g_autoptr (OstreeSysroot ) sysroot = NULL ;
275+ OstreeDeployment * booted = NULL ;
276+ if (!load_booted_deployment ( sysroot_path , & sysroot , & booted , cancellable , error ))
258277 return FALSE;
259278
260- OstreeDeployment * booted = ostree_sysroot_get_booted_deployment (sysroot );
261- if (!booted )
262- return glnx_throw (error , "Not booted into any deployment" );
263-
264279 if (argc < 2 )
265280 {
266281 /* diff booted against pending or rollback deployment */
0 commit comments