Skip to content

Commit ff4deab

Browse files
authored
Merge branch 'OpenAtom-Linyaps:master' into master
2 parents cf0654a + 1e9c45d commit ff4deab

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

libs/linglong/src/linglong/repo/ostree_repo.cpp

+52-1
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,50 @@ utils::error::Result<QString> commitDirToRepo(std::vector<GFile *> dirs,
358358
return commit;
359359
}
360360

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+
361405
utils::error::Result<void>
362406
updateOstreeRepoConfig(OstreeRepo *repo,
363407
const linglong::api::types::v1::RepoConfigV2 &config,
@@ -432,7 +476,6 @@ updateOstreeRepoConfig(OstreeRepo *repo,
432476

433477
GKeyFile *configKeyFile = ostree_repo_get_config(repo);
434478
Q_ASSERT(configKeyFile != nullptr);
435-
QDir a;
436479

437480
g_key_file_set_string(configKeyFile, "core", "min-free-space-size", "600MB");
438481
if (!parent.isEmpty()) {
@@ -466,6 +509,7 @@ createOstreeRepo(const QDir &location,
466509
repoPath = g_file_new_for_path(location.absolutePath().toUtf8());
467510
ostreeRepo = ostree_repo_new(repoPath);
468511
Q_ASSERT(ostreeRepo != nullptr);
512+
469513
if (ostree_repo_create(ostreeRepo, OSTREE_REPO_MODE_BARE_USER_ONLY, nullptr, &gErr) == FALSE) {
470514
return LINGLONG_ERR("ostree_repo_create", gErr);
471515
}
@@ -722,13 +766,20 @@ OSTreeRepo::OSTreeRepo(const QDir &path,
722766
g_autoptr(OstreeRepo) ostreeRepo = nullptr;
723767

724768
this->repoDir = path;
769+
725770
{
726771
LINGLONG_TRACE("use linglong repo at " + path.absolutePath());
727772

728773
repoPath = g_file_new_for_path(this->ostreeRepoDir().absolutePath().toLocal8Bit());
729774
ostreeRepo = ostree_repo_new(repoPath);
730775
Q_ASSERT(ostreeRepo != nullptr);
731776
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+
732783
this->ostreeRepo.reset(static_cast<OstreeRepo *>(g_steal_pointer(&ostreeRepo)));
733784

734785
auto ret = linglong::repo::RepoCache::create(

0 commit comments

Comments
 (0)