kinit: different take on duplicate URLs

to not pass temporary files more than once to programs

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-05-25 11:37:21 +03:00
parent 07b318f9ac
commit cea5737e95

View file

@ -396,11 +396,28 @@ bool KLauncherAdaptor::start_service_by_storage_id(const QString &serviceName,
}
kDebug() << "downloaded" << prettyurl << "to" << urldestination;
downloaded.insert(urldestination, realurl);
// URLs may not be unique
int indexofurl = programandargs.indexOf(url);
while (indexofurl != -1) {
// URLs may not be unique, don't download more than once
const int indexofurl = programandargs.indexOf(url);
if (indexofurl == -1) {
// this should never happen but warn just in case
kWarning() << "could not find the index of" << url;
} else {
programandargs.replace(indexofurl, urldestination);
indexofurl = programandargs.indexOf(url);
bool isfirst = true;
QMutableListIterator<QString> iter(programandargs);
while (iter.hasNext()) {
if (iter.next() == url) {
if (isfirst) {
// first already replaced
isfirst = false;
continue;
} else {
// every other occurance is removed
kDebug() << "removing duplicate of downloaded URL" << url;
iter.remove();
}
}
}
}
}
}