@@ -358,6 +358,50 @@ utils::error::Result<QString> commitDirToRepo(std::vector<GFile *> dirs,
358
358
return commit;
359
359
}
360
360
361
+ utils::error::Result<void > initOstreeRepoConfig (
362
+ OstreeRepo *repo, const linglong::api::types::v1::RepoConfigV2 &config) noexcept
363
+ {
364
+ LINGLONG_TRACE (" init ostree repo config" );
365
+ g_autoptr (GError) gErr = nullptr ;
366
+
367
+ const auto &defaultRepo = getDefaultRepo (config);
368
+
369
+ g_auto (GStrv) remoteNames = ostree_repo_remote_list (repo, nullptr );
370
+ if (remoteNames) {
371
+ return LINGLONG_OK;
372
+ }
373
+ const std::string &remoteUrl = defaultRepo.url + " /repos/" + defaultRepo.name ;
374
+ g_autoptr (GVariant) options = NULL ;
375
+ GVariantBuilder builder;
376
+ g_variant_builder_init (&builder, G_VARIANT_TYPE (" a{sv}" ));
377
+ g_variant_builder_add (&builder, " {sv}" , " gpg-verify" , g_variant_new_boolean (FALSE ));
378
+ g_variant_builder_add (&builder, " {sv}" , " http2" , g_variant_new_boolean (FALSE ));
379
+ options = g_variant_ref_sink (g_variant_builder_end (&builder));
380
+
381
+ if (ostree_repo_remote_change (repo,
382
+ nullptr ,
383
+ OSTREE_REPO_REMOTE_CHANGE_ADD,
384
+ defaultRepo.alias .value_or (defaultRepo.name ).c_str (),
385
+ remoteUrl.c_str (),
386
+ options,
387
+ nullptr ,
388
+ &gErr )
389
+ == FALSE ) {
390
+ return LINGLONG_ERR (" ostree_repo_remote_change" , gErr );
391
+ }
392
+
393
+ GKeyFile *configKeyFile = ostree_repo_get_config (repo);
394
+ Q_ASSERT (configKeyFile != nullptr );
395
+
396
+ g_key_file_set_string (configKeyFile, " core" , " min-free-space-size" , " 600MB" );
397
+
398
+ if (ostree_repo_write_config (repo, configKeyFile, &gErr ) == FALSE ) {
399
+ return LINGLONG_ERR (" ostree_repo_write_config" , gErr );
400
+ }
401
+
402
+ return LINGLONG_OK;
403
+ }
404
+
361
405
utils::error::Result<void >
362
406
updateOstreeRepoConfig (OstreeRepo *repo,
363
407
const linglong::api::types::v1::RepoConfigV2 &config,
@@ -432,7 +476,6 @@ updateOstreeRepoConfig(OstreeRepo *repo,
432
476
433
477
GKeyFile *configKeyFile = ostree_repo_get_config (repo);
434
478
Q_ASSERT (configKeyFile != nullptr );
435
- QDir a;
436
479
437
480
g_key_file_set_string (configKeyFile, " core" , " min-free-space-size" , " 600MB" );
438
481
if (!parent.isEmpty ()) {
@@ -466,6 +509,7 @@ createOstreeRepo(const QDir &location,
466
509
repoPath = g_file_new_for_path (location.absolutePath ().toUtf8 ());
467
510
ostreeRepo = ostree_repo_new (repoPath);
468
511
Q_ASSERT (ostreeRepo != nullptr );
512
+
469
513
if (ostree_repo_create (ostreeRepo, OSTREE_REPO_MODE_BARE_USER_ONLY, nullptr , &gErr ) == FALSE ) {
470
514
return LINGLONG_ERR (" ostree_repo_create" , gErr );
471
515
}
@@ -722,13 +766,20 @@ OSTreeRepo::OSTreeRepo(const QDir &path,
722
766
g_autoptr (OstreeRepo) ostreeRepo = nullptr ;
723
767
724
768
this ->repoDir = path;
769
+
725
770
{
726
771
LINGLONG_TRACE (" use linglong repo at " + path.absolutePath ());
727
772
728
773
repoPath = g_file_new_for_path (this ->ostreeRepoDir ().absolutePath ().toLocal8Bit ());
729
774
ostreeRepo = ostree_repo_new (repoPath);
730
775
Q_ASSERT (ostreeRepo != nullptr );
731
776
if (ostree_repo_open (ostreeRepo, nullptr , &gErr ) == TRUE ) {
777
+ auto result = initOstreeRepoConfig (ostreeRepo, this ->cfg );
778
+ if (!result) {
779
+ qCritical () << LINGLONG_ERRV (result);
780
+ qFatal (" abort" );
781
+ }
782
+
732
783
this ->ostreeRepo .reset (static_cast <OstreeRepo *>(g_steal_pointer (&ostreeRepo)));
733
784
734
785
auto ret = linglong::repo::RepoCache::create (
0 commit comments