installer: add cache path on userdata (#22045)

* installer: add cache path on userdata

* keep legacy as is

* only copy

* print cache path

* comment
pull/22048/head
Adeeb Shihadeh 2021-08-26 10:43:47 -07:00 committed by GitHub
parent 822e93af3a
commit 6c25b44369
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions

View File

@ -19,12 +19,13 @@
#ifdef QCOM
#define CONTINUE_PATH "/data/data/com.termux/files/continue.sh"
#define CACHE_PATH "/system/comma/openpilot"
#else
#define CONTINUE_PATH "/data/continue.sh"
#define CACHE_PATH "/usr/comma/openpilot"
#endif
// TODO: remove the other paths after a bit
const QList<QString> CACHE_PATHS = {"/data/openpilot.cache", "/system/comma/openpilot", "/usr/comma/openpilot"};
#define INSTALL_PATH "/data/openpilot"
#define TMP_INSTALL_PATH "/data/tmppilot"
@ -106,9 +107,18 @@ void Installer::doInstall() {
// cleanup
run("rm -rf " TMP_INSTALL_PATH " " INSTALL_PATH);
// find the cache path
QString cache;
for (const QString &path : CACHE_PATHS) {
if (QDir(path).exists()) {
cache = path;
break;
}
}
// do the install
if (QDir(CACHE_PATH).exists()) {
cachedFetch();
if (!cache.isEmpty()) {
cachedFetch(cache);
} else {
freshClone();
}
@ -120,10 +130,10 @@ void Installer::freshClone() {
"--depth=1", "--recurse-submodules", TMP_INSTALL_PATH});
}
void Installer::cachedFetch() {
qDebug() << "Fetching with cache";
void Installer::cachedFetch(const QString &cache) {
qDebug() << "Fetching with cache: " << cache;
run("cp -rp " CACHE_PATH " " TMP_INSTALL_PATH);
run(QString("cp -rp %1 %2").arg(cache, TMP_INSTALL_PATH).toStdString().c_str());
int err = chdir(TMP_INSTALL_PATH);
assert(err == 0);
run("git remote set-branches --add origin " BRANCH);

View File

@ -24,5 +24,5 @@ private:
void doInstall();
void freshClone();
void cachedFetch();
void cachedFetch(const QString &cache);
};