Skip to content

Commit

Permalink
only write checksum file after unzipping
Browse files Browse the repository at this point in the history
  • Loading branch information
matcool committed Oct 10, 2023
1 parent c87e8f6 commit b4fbea5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions loader/src/loader/Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class Index::Impl final {
friend class Index;

void cleanupItems();
void downloadIndex();
void downloadIndex(std::string commitHash = "");
void checkForUpdates();
void updateFromLocalTree();
void installNext(size_t index, IndexInstallList const& list);
Expand Down Expand Up @@ -296,7 +296,7 @@ bool Index::hasTriedToUpdate() const {
return m_impl->m_triedToUpdate;
}

void Index::Impl::downloadIndex() {
void Index::Impl::downloadIndex(std::string commitHash) {
log::debug("Downloading index");

IndexUpdateEvent(UpdateProgress(0, "Beginning download")).post();
Expand All @@ -307,7 +307,7 @@ void Index::Impl::downloadIndex() {
.join("index-download")
.fetch("https://github.com/geode-sdk/mods/zipball/main")
.into(targetFile)
.then([this, targetFile](auto) {
.then([this, targetFile, commitHash](auto) {
auto targetDir = dirs::getIndexDir() / "v0";
// delete old unzipped index
try {
Expand All @@ -333,6 +333,10 @@ void Index::Impl::downloadIndex() {

// remove the directory github adds to the root of the zip
(void)flattenGithubRepo(targetDir);
if (!commitHash.empty()) {
auto const checksumPath = dirs::getIndexDir() / ".checksum";
(void)file::writeString(checksumPath, commitHash);
}

Loader::get()->queueInMainThread([this] {
// update index
Expand Down Expand Up @@ -387,8 +391,7 @@ void Index::Impl::checkForUpdates() {
}
// otherwise save hash and download source
else {
(void)file::writeString(checksum, newSHA);
this->downloadIndex();
this->downloadIndex(newSHA);
}
})
.expect([](std::string const& err) {
Expand Down

0 comments on commit b4fbea5

Please sign in to comment.