From cd6bd12c80f110139fe70dc606dea1aeffa5c7d2 Mon Sep 17 00:00:00 2001 From: kamiyadm Date: Mon, 15 Jan 2024 18:21:01 +0800 Subject: [PATCH] fix: print progress error Use pull() and checkout() instead of pullAll() and checkoutAll while fetching dependency. Log: --- src/linglong/builder/depend_fetcher.cpp | 119 +++++++++++++----------- 1 file changed, 65 insertions(+), 54 deletions(-) diff --git a/src/linglong/builder/depend_fetcher.cpp b/src/linglong/builder/depend_fetcher.cpp index 5bf325bdc..acd0a23be 100644 --- a/src/linglong/builder/depend_fetcher.cpp +++ b/src/linglong/builder/depend_fetcher.cpp @@ -63,69 +63,80 @@ void DependFetcher::printProgress(const uint &progress, const QString &speed) linglong::util::Error DependFetcher::fetch(const QString &subPath, const QString &targetPath) { - // depends from remote > depends from local - ref.repo = BuilderConfig::instance()->remoteRepoName; - ref.channel = "linglong"; - - // FIXME(black_desk): - // 1. Offline should not only be an option of builder, but also a work - // mode argument passed to repo, which prevent all network request. - // 2. For now we just leave these code here, we will refactor them later. - if (BuilderConfig::instance()->getOffline()) { - ref = *ostree.localLatestRef(ref); - - printer.printMessage(QString("offline dependency: %1 %2").arg(ref.appId).arg(ref.version)); - } else { - ref = ostree.remoteLatestRef(ref); - printer.printReplacedText(QString("%1%2%3%4") - .arg(ref.appId, -20) - .arg(ref.version, -15) - .arg(ref.module, -15) - .arg("...")); - auto ret = ostree.pullAll(ref, true); - if (!ret.has_value()) { - return WrapError(NewError(ret.error().code(), ret.error().message()), - "pull " + ref.toString() + " failed"); - } - } + auto pullAndCheckout = [&]() -> linglong::util::Error { + // FIXME(black_desk): + // 1. Offline should not only be an option of builder, but also a work + // mode argument passed to repo, which prevent all network request. + // 2. For now we just leave these code here, we will refactor them later. + if (BuilderConfig::instance()->getOffline()) { + ref = *ostree.localLatestRef(ref); - QDir targetParentDir(targetPath); - targetParentDir.cdUp(); - targetParentDir.mkpath("."); - { - printer.printReplacedText(QString("%1%2%3%4") - .arg(ref.appId, -20) - .arg(ref.version, -15) - .arg(ref.module, -15) - .arg("checkout")); - auto ret = ostree.checkoutAll(ref, subPath, targetPath); - if (!ret.has_value()) { - return WrapError(NewError(ret.error().code(), ret.error().message()), - QString("ostree checkout %1 failed").arg(ref.toLocalRefString())); + printer.printMessage( + QString("offline dependency: %1 %2").arg(ref.appId).arg(ref.version)); + } else { + ref = ostree.remoteLatestRef(ref); + printer.printReplacedText(QString("%1%2%3%4") + .arg(ref.appId, -20) + .arg(ref.version, -15) + .arg(ref.module, -15) + .arg("...")); + auto ret = ostree.pull(ref, true); + if (!ret.has_value()) { + return WrapError(NewError(ret.error().code(), ret.error().message()), + "pull " + ref.toString() + " failed"); + } } - printer.printReplacedText(QString("%1%2%3%4") - .arg(ref.appId, -20) - .arg(ref.version, -15) - .arg(ref.module, -15) - .arg("complete\n")); - } - // for app,lib. if the dependType match runtime, should be submitted together. - if (dd_ptr->dependType == DependTypeRuntime) { - auto targetInstallPath = dd_ptr->project->config().cacheAbsoluteFilePath( - { "overlayfs", "up", dd_ptr->project->config().targetInstallPath("") }); + QDir targetParentDir(targetPath); + targetParentDir.cdUp(); + targetParentDir.mkpath("."); { - auto ret = ostree.checkoutAll(ref, subPath, targetInstallPath); + printer.printReplacedText(QString("%1%2%3%4") + .arg(ref.appId, -20) + .arg(ref.version, -15) + .arg(ref.module, -15) + .arg("checkout")); + auto ret = ostree.checkout(ref, subPath, targetPath); if (!ret.has_value()) { return WrapError(NewError(ret.error().code(), ret.error().message()), - QString("ostree checkout %1 with subpath '%2' to %3") - .arg(ref.toLocalRefString()) - .arg(subPath) - .arg(targetPath)); + QString("ostree checkout %1 failed").arg(ref.toLocalRefString())); + } + + printer.printReplacedText(QString("%1%2%3%4") + .arg(ref.appId, -20) + .arg(ref.version, -15) + .arg(ref.module, -15) + .arg("complete\n")); + } + // for app,lib. if the dependType match runtime, should be submitted together. + if (dd_ptr->dependType == DependTypeRuntime) { + auto targetInstallPath = dd_ptr->project->config().cacheAbsoluteFilePath( + { "overlayfs", "up", dd_ptr->project->config().targetInstallPath("") }); + { + auto ret = ostree.checkout(ref, subPath, targetInstallPath); + if (!ret.has_value()) { + return WrapError(NewError(ret.error().code(), ret.error().message()), + QString("ostree checkout %1 with subpath '%2' to %3") + .arg(ref.toLocalRefString()) + .arg(subPath) + .arg(targetPath)); + } } } + return {}; + }; + + // pull the package data which module is runtime + ref.channel = "linglong"; + ref.module = "runtime"; + auto err = pullAndCheckout(); + if (err) { + return err; } - return {}; + + // pull the package data which module is devel + ref.module = "devel"; + return pullAndCheckout(); } } // namespace builder