11/*
2- * SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
2+ * SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
33 *
44 * SPDX-License-Identifier: LGPL-3.0-or-later
55 */
1212#include " linglong/repo/config.h"
1313#include " linglong/repo/migrate.h"
1414#include " linglong/repo/ostree_repo.h"
15+ #include " linglong/utils/file.h"
1516#include " ocppi/cli/CLI.hpp"
1617#include " ocppi/cli/crun/Crun.hpp"
1718
@@ -23,16 +24,18 @@ namespace {
2324void withDBusDaemon (ocppi::cli::CLI &cli)
2425{
2526 auto config = linglong::repo::loadConfig (
26- { LINGLONG_ROOT " /config.yaml" , LINGLONG_DATA_DIR " /config.yaml" });
27+ std::vector<std::filesystem::path>{ LINGLONG_ROOT " /config.yaml" ,
28+ LINGLONG_DATA_DIR " /config.yaml" });
2729 if (!config.has_value ()) {
2830 LogE (" load config failed: {}" , config.error ());
2931 QCoreApplication::exit (-1 );
3032 return ;
3133 }
3234
33- auto repoRoot = QDir (LINGLONG_ROOT );
34- if (!repoRoot.exists () && !repoRoot.mkpath (" ." )) {
35- LogE (" failed to create repository directory {}" , repoRoot.absolutePath ().toStdString ());
35+ std::filesystem::path repoRoot (LINGLONG_ROOT );
36+ auto res = linglong::utils::ensureDirectory (repoRoot);
37+ if (!res) {
38+ LogE (" failed to create repository directory {}" , res.error ());
3639 std::abort ();
3740 }
3841
@@ -41,7 +44,14 @@ void withDBusDaemon(ocppi::cli::CLI &cli)
4144 LogE (" failed to migrate repository" );
4245 QCoreApplication::exit (-1 );
4346 }
44- auto *ostreeRepo = new linglong::repo::OSTreeRepo (repoRoot, *config);
47+
48+ auto repo = linglong::repo::OSTreeRepo::create (repoRoot, *config);
49+ if (!repo) {
50+ LogE (" failed to create repo: {}" , repo.error ());
51+ QCoreApplication::exit (-1 );
52+ return ;
53+ }
54+ auto *ostreeRepo = std::move (repo).value ().release ();
4555 ostreeRepo->setParent (QCoreApplication::instance ());
4656 auto result = ostreeRepo->fixExportAllEntries ();
4757 if (!result.has_value ()) {
@@ -91,20 +101,28 @@ void withoutDBusDaemon(ocppi::cli::CLI &cli)
91101 LogI (" Running linglong package manager without dbus daemon..." );
92102
93103 auto config = linglong::repo::loadConfig (
94- { LINGLONG_ROOT " /config.yaml" , LINGLONG_DATA_DIR " /config.yaml" });
104+ std::vector<std::filesystem::path>{ LINGLONG_ROOT " /config.yaml" ,
105+ LINGLONG_DATA_DIR " /config.yaml" });
95106 if (!config.has_value ()) {
96107 LogE (" load config failed: {}" , config.error ());
97108 QCoreApplication::exit (-1 );
98109 return ;
99110 }
100111
101- auto repoRoot = QDir (LINGLONG_ROOT );
102- if (!repoRoot.exists () && !repoRoot.mkpath (" ." )) {
103- LogE (" failed to create repository directory {}" , repoRoot.absolutePath ().toStdString ());
112+ std::filesystem::path repoRoot (LINGLONG_ROOT );
113+ auto res = linglong::utils::ensureDirectory (repoRoot);
114+ if (!res) {
115+ LogE (" failed to create repository directory {}" , res.error ());
104116 std::abort ();
105117 }
106118
107- auto *ostreeRepo = new linglong::repo::OSTreeRepo (repoRoot, *config);
119+ auto repo = linglong::repo::OSTreeRepo::create (repoRoot, *config);
120+ if (!repo) {
121+ LogE (" failed to create repo: {}" , repo.error ());
122+ QCoreApplication::exit (-1 );
123+ return ;
124+ }
125+ auto *ostreeRepo = std::move (repo).value ().release ();
108126 ostreeRepo->setParent (QCoreApplication::instance ());
109127 auto result = ostreeRepo->fixExportAllEntries ();
110128 if (!result.has_value ()) {
0 commit comments