1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
#include "rust-apt/src/raw/progress.rs"
#include <apt-pkg/acquire-worker.h>
#include <apt-pkg/error.h>
#include "progress.h"
/// AcqTextStatus modeled from in apt-private/acqprogress.cc
///
/// AcqTextStatus::AcqTextStatus - Constructor
AcqTextStatus::AcqTextStatus(DynAcquireProgress& callback)
: pkgAcquireStatus(), callback(callback) {}
/// Called when progress has started.
///
/// We do not print anything here to remain consistent with apt.
/// lastline length is set to 0 to ensure consistency when progress begins.
void AcqTextStatus::Start() {
pkgAcquireStatus::Start();
start(callback);
ID = 1;
}
/// Internal function to assign the correct ID to an Item.
///
/// We can likely move this into the rust side with a refactor of the items.
/// Not sure it that should be done, we'll see in the future.
void AcqTextStatus::AssignItemID(pkgAcquire::ItemDesc& Itm) {
if (Itm.Owner->ID == 0) Itm.Owner->ID = ID++;
}
/// Called when an item is confirmed to be up-to-date.
///
/// Prints out the short description and the expected size.
void AcqTextStatus::IMSHit(pkgAcquire::ItemDesc& Itm) {
AssignItemID(Itm);
hit(callback, Itm.Owner->ID, Itm.Description);
Update = true;
}
/// Called when an Item has started to download
///
/// Prints out the short description and the expected size.
void AcqTextStatus::Fetch(pkgAcquire::ItemDesc& Itm) {
Update = true;
if (Itm.Owner->Complete == true) return;
AssignItemID(Itm);
fetch(callback, Itm.Owner->ID, Itm.Description, Itm.Owner->FileSize);
}
/// Called when an item is successfully and completely fetched.
///
/// We don't print anything here to remain consistent with apt.
void AcqTextStatus::Done(pkgAcquire::ItemDesc& Itm) {
Update = true;
AssignItemID(Itm);
done(callback);
}
/// Called when an Item fails to download.
///
/// Print out the ErrorText for the Item.
void AcqTextStatus::Fail(pkgAcquire::ItemDesc& Itm) {
AssignItemID(Itm);
fail(callback, Itm.Owner->ID, Itm.Description, Itm.Owner->Status, Itm.Owner->ErrorText);
Update = true;
}
/// Called when progress has finished.
///
/// prints out the bytes downloaded and the overall average line speed.
void AcqTextStatus::Stop() {
pkgAcquireStatus::Stop();
stop(callback, FetchedBytes, ElapsedTime, CurrentCPS, _error->PendingError());
}
/// Called periodically to provide the overall progress information
///
/// Draws the current progress.
/// Each line has an overall percent meter and a per active item status
/// meter along with an overall bandwidth and ETA indicator.
bool AcqTextStatus::Pulse(pkgAcquire* Owner) {
pkgAcquireStatus::Pulse(Owner);
rust::vec<Worker> list;
for (pkgAcquire::Worker* I = Owner->WorkersBegin(); I != 0; I = Owner->WorkerStep(I)) {
// There is no item running
if (I->CurrentItem == 0) {
list.push_back(Worker{
false,
I->Status,
0,
"",
"",
0,
0,
false,
});
continue;
}
list.push_back(Worker{
true,
I->Status,
I->CurrentItem->Owner->ID,
I->CurrentItem->ShortDesc,
I->CurrentItem->Owner->ActiveSubprocess,
I->CurrentItem->CurrentSize,
I->CurrentItem->TotalSize,
I->CurrentItem->Owner->Complete,
});
}
pulse(callback, list, Percent, TotalBytes, CurrentBytes, CurrentCPS);
Update = true;
return true;
}
/// Not Yet Implemented
///
/// Invoked when the user should be prompted to change the inserted removable media.
bool AcqTextStatus::MediaChange(std::string Media, std::string Drive) {
(void)Drive;
(void)Media;
// If we do not output on a terminal and one of the options to avoid user
// interaction is given, we assume that no user is present who could react
// on your media change request
// if (isatty(STDOUT_FILENO) != 1 && Quiet >= 2 &&
// (_config->FindB("APT::Get::Assume-Yes", false) == true ||
// _config->FindB("APT::Get::Force-Yes", false) == true ||
// _config->FindB("APT::Get::Trivial-Only", false) == true))
// return false;
// clearLastLine();
// ioprintf(out,
// "Media change: please insert the disc labeled\n"
// " '%s'\n"
// "in the drive '%s' and press [Enter]\n",
// Media.c_str(), Drive.c_str());
// char C = 0;
// bool bStatus = true;
// while (C != '\n' && C != '\r') {
// int len = read(STDIN_FILENO, &C, 1);
// if (C == 'c' || len <= 0) {
// bStatus = false;
// break;
// }
// }
// if (bStatus) Update = true;
// return bStatus;
// I'm not sure what to return here.
// Will need to test media swaps at some point
return false;
}
/// Not Yet Implemented
///
/// Ask the user for confirmation of changes to infos about a repository
/// Must return true if the user accepts or false if not
bool AcqTextStatus::ReleaseInfoChanges(
metaIndex const* const L,
metaIndex const* const N,
std::vector<ReleaseInfoChange>&& Changes
) {
(void)L;
(void)N;
(void)Changes;
// if (Quiet >= 2 || isatty(STDOUT_FILENO) != 1 || isatty(STDIN_FILENO) != 1 ||
// _config->FindB("APT::Get::Update::InteractiveReleaseInfoChanges", false) == false)
// return pkgAcquireStatus::ReleaseInfoChanges(nullptr, nullptr, std::move(Changes));
// _error->PushToStack();
// auto const confirmed = pkgAcquireStatus::ReleaseInfoChanges(L, N,
// std::move(Changes)); if (confirmed == true) { _error->MergeWithStack();
// return true;
// }
// clearLastLine();
// _error->DumpErrors(out, GlobalError::NOTICE, false);
// _error->RevertToStack();
// return YnPrompt(_("Do you want to accept these changes and continue updating from this
// repository?"), false, false, out, out);
// Not yet implemented. Remove return true when it is.
return true;
}
/// Calls for OpProgress usage.
OpProgressWrapper::OpProgressWrapper(DynOperationProgress& callback) : callback(callback) {}
void OpProgressWrapper::Update() { op_update(callback, Op, Percent); }
void OpProgressWrapper::Done() { op_done(callback); }
/// Calls for InstallProgress usage.
PackageManagerWrapper::PackageManagerWrapper(DynInstallProgress& callback) : callback(callback) {}
bool PackageManagerWrapper::StatusChanged(
std::string pkgname,
unsigned int steps_done,
unsigned int total_steps,
std::string action
) {
inst_status_changed(callback, pkgname, steps_done, total_steps, action);
return true;
}
void PackageManagerWrapper::Error(
std::string pkgname,
unsigned int steps_done,
unsigned int total_steps,
std::string error
) {
inst_error(callback, pkgname, steps_done, total_steps, error);
}
|