Skip to content

Commit

Permalink
fix: print progress error
Browse files Browse the repository at this point in the history
Use pull() and checkout() instead of pullAll() and
checkoutAll while fetching dependency.

Log:
  • Loading branch information
kamiyadm authored and black-desk committed Jan 16, 2024
1 parent 6af65ae commit cd6bd12
Showing 1 changed file with 65 additions and 54 deletions.
119 changes: 65 additions & 54 deletions src/linglong/builder/depend_fetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cd6bd12

Please sign in to comment.